Created
November 1, 2022 11:16
-
-
Save kristersd/6a1f64022e68843350e1969c0fe2923d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const InputSelect = ({options, invalidate, onChange, className, muteEmpty, children, ...props}) => { | |
useEffect(() => { | |
if (!invalidate) { | |
return; | |
} | |
if (props.value && !options.some(({value}) => value === props.value)) { | |
onChange({ | |
target: { | |
type: "select", | |
value: options[0]?.value ?? "", | |
}, | |
}); | |
} | |
}, [invalidate, options, onChange, props.value]); | |
return ( | |
<Input {...props} | |
type="select" | |
className={classNames({ | |
"custom-select": true, | |
"custom-select-sm": props.bsSize === "sm", | |
"custom-select-lg": props.bsSize === "lg", | |
[className]: !!className, | |
"text-muted": muteEmpty && !props.value, | |
})} | |
onChange={onChange}> | |
{children} | |
</Input> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment