Fix SelectWithInput styles and functionality
* Adapts styles for CSS modules * Add name to errors * Properly sends validity
This commit is contained in:
parent
1c805e3f88
commit
1f26b0afc8
2 changed files with 42 additions and 38 deletions
|
|
@ -1,23 +1,11 @@
|
|||
.SelectWithItem {
|
||||
.InputSet {
|
||||
.set {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: $unit;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.SelectTrigger {
|
||||
flex-grow: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.Input {
|
||||
flex-grow: 0;
|
||||
text-align: right;
|
||||
width: 13rem;
|
||||
}
|
||||
}
|
||||
|
||||
.errors {
|
||||
.errors {
|
||||
color: $error;
|
||||
display: none;
|
||||
padding: $unit 0;
|
||||
|
|
@ -25,5 +13,4 @@
|
|||
&.visible {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,13 +59,13 @@ const SelectWithInput = ({
|
|||
|
||||
// Classes
|
||||
const inputClasses = classNames({
|
||||
Bound: true,
|
||||
Hidden: currentItemSkill?.id === 0,
|
||||
fullHeight: true,
|
||||
range: true,
|
||||
})
|
||||
|
||||
const errorClasses = classNames({
|
||||
errors: true,
|
||||
visible: error !== '',
|
||||
[styles.errors]: true,
|
||||
[styles.visible]: error !== '',
|
||||
})
|
||||
|
||||
// Hooks
|
||||
|
|
@ -127,18 +127,24 @@ const SelectWithInput = ({
|
|||
let error = ''
|
||||
|
||||
if (currentItemSkill) {
|
||||
if (value < currentItemSkill.minValue) {
|
||||
if (!currentItemSkill.fractional && value && value % 1 != 0) {
|
||||
error = t(`${object}.errors.value_not_whole`, {
|
||||
name: currentItemSkill.name[locale],
|
||||
})
|
||||
} else if (value < currentItemSkill.minValue) {
|
||||
error = t(`${object}.errors.value_too_low`, {
|
||||
name: currentItemSkill.name[locale],
|
||||
minValue: currentItemSkill.minValue,
|
||||
})
|
||||
} else if (value > currentItemSkill.maxValue) {
|
||||
error = t(`${object}.errors.value_too_high`, {
|
||||
name: currentItemSkill.name[locale],
|
||||
maxValue: currentItemSkill.maxValue,
|
||||
})
|
||||
} else if (!currentItemSkill.fractional && value % 1 != 0) {
|
||||
error = t(`${object}.errors.value_not_whole`)
|
||||
} else if (!value || value <= 0) {
|
||||
error = t(`${object}.errors.value_empty`)
|
||||
error = t(`${object}.errors.value_empty`, {
|
||||
name: currentItemSkill.name[locale],
|
||||
})
|
||||
} else {
|
||||
error = ''
|
||||
}
|
||||
|
|
@ -146,7 +152,13 @@ const SelectWithInput = ({
|
|||
|
||||
setError(error)
|
||||
|
||||
return error.length === 0
|
||||
if (error.length > 0) {
|
||||
sendValidity(false)
|
||||
return false
|
||||
} else {
|
||||
sendValidity(true)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
const rangeString = () => {
|
||||
|
|
@ -162,17 +174,19 @@ const SelectWithInput = ({
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="SelectWithItem">
|
||||
<div className="InputSet">
|
||||
<div>
|
||||
<div className={styles.set}>
|
||||
<Select
|
||||
key={`${currentItemSkill?.name.en}_type`}
|
||||
value={`${currentItemSkill ? currentItemSkill.id : 0}`}
|
||||
open={open}
|
||||
trigger={{
|
||||
className: 'grow',
|
||||
}}
|
||||
disabled={selectDisabled}
|
||||
onValueChange={handleSelectChange}
|
||||
onOpenChange={changeOpen}
|
||||
onClose={onClose}
|
||||
triggerClass="modal"
|
||||
overlayVisible={false}
|
||||
>
|
||||
{generateOptions()}
|
||||
|
|
@ -181,13 +195,16 @@ const SelectWithInput = ({
|
|||
<Input
|
||||
value={fieldInputValue}
|
||||
className={inputClasses}
|
||||
fieldsetClassName={classNames({
|
||||
hidden: currentItemSkill?.id === 0,
|
||||
})}
|
||||
wrapperClassName="fullHeight"
|
||||
type="number"
|
||||
placeholder={rangeString()}
|
||||
min={currentItemSkill?.minValue}
|
||||
max={currentItemSkill?.maxValue}
|
||||
step="1"
|
||||
onChange={handleInputChange}
|
||||
visible={currentItemSkill ? 'true' : 'false'}
|
||||
ref={input}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue