mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-23 03:54:21 +00:00
🐛 Allow managed Form.Select
and Form.Multiselect
to have selected options
This commit is contained in:
parent
e8f06c4018
commit
409922afb1
2 changed files with 4 additions and 4 deletions
|
@ -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(
|
const onSimpleChangeWrapped = React.useCallback(
|
||||||
values => {
|
values => {
|
||||||
onSimpleChange?.(values.map((val: string) => options[val]))
|
onSimpleChange?.(values.map((val: string) => options[val]))
|
||||||
|
@ -35,7 +35,7 @@ export function FormMultiselect({label, validity, pairProps, labelProps, onSimpl
|
||||||
)
|
)
|
||||||
|
|
||||||
const optionComponents = React.useMemo(
|
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],
|
[options],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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(
|
const onSimpleChangeWrapped = React.useCallback(
|
||||||
value => {
|
value => {
|
||||||
onSimpleChange?.(options[value])
|
onSimpleChange?.(options[value])
|
||||||
|
@ -35,7 +35,7 @@ export function FormSelect({label, validity, options, pairProps, labelProps, onS
|
||||||
)
|
)
|
||||||
|
|
||||||
const optionComponents = React.useMemo(
|
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],
|
[options],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue