1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-22 19:44:21 +00:00

🐛 Allow managed Form.Select and Form.Multiselect to have selected options

This commit is contained in:
Steffo 2021-10-11 17:53:51 +02:00
parent e8f06c4018
commit 409922afb1
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 4 additions and 4 deletions

View file

@ -26,7 +26,7 @@ export interface FormMultiselectProps extends MultiselectProps {
}
export function FormMultiselect({label, validity, pairProps, labelProps, onSimpleChange, options, ...props}: FormMultiselectProps): JSX.Element {
export function FormMultiselect({label, validity, pairProps, labelProps, onSimpleChange, options, value, ...props}: FormMultiselectProps): JSX.Element {
const onSimpleChangeWrapped = React.useCallback(
values => {
onSimpleChange?.(values.map((val: string) => options[val]))
@ -35,7 +35,7 @@ export function FormMultiselect({label, validity, pairProps, labelProps, onSimpl
)
const optionComponents = React.useMemo(
() => Object.keys(options).map(key => <Multiselect.Option value={key} key={key}/>),
() => Object.keys(options).map(key => <Multiselect.Option value={key} key={key} selected={value?.includes(key)}/>),
[options],
)

View file

@ -26,7 +26,7 @@ export interface FormSelectProps extends SelectProps {
}
export function FormSelect({label, validity, options, pairProps, labelProps, onSimpleChange, ...props}: FormSelectProps): JSX.Element {
export function FormSelect({label, validity, options, pairProps, labelProps, onSimpleChange, value, ...props}: FormSelectProps): JSX.Element {
const onSimpleChangeWrapped = React.useCallback(
value => {
onSimpleChange?.(options[value])
@ -35,7 +35,7 @@ export function FormSelect({label, validity, options, pairProps, labelProps, onS
)
const optionComponents = React.useMemo(
() => Object.keys(options).map(key => <Select.Option value={key} key={key}/>),
() => Object.keys(options).map(key => <Select.Option value={key} key={key} selected={value === key}/>),
[options],
)