mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-23 07:42:10 +00:00
fix issue with dropdown
This commit is contained in:
parent
125c6417cf
commit
c018f95e70
@ -33,13 +33,31 @@ export interface ComponentProps {
|
||||
const Dropdown: FunctionComponent<ComponentProps> = (
|
||||
props: ComponentProps
|
||||
): ReactElement => {
|
||||
|
||||
const getDropdownOptionFromValue: Function = (value: undefined | DropdownValue | DropdownOption | Array<DropdownOption>): DropdownOption | Array<DropdownOption> => {
|
||||
|
||||
if(Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (!Array.isArray(value) && typeof value === 'string' || typeof value === 'number') {
|
||||
return props.options.find((option) => {
|
||||
return option.value === value;
|
||||
}) as DropdownOption | Array<DropdownOption>;
|
||||
} else {
|
||||
return value as DropdownOption | Array<DropdownOption>;
|
||||
}
|
||||
}
|
||||
|
||||
const [value, setValue] = useState<
|
||||
DropdownOption | Array<DropdownOption> | undefined
|
||||
>(props.initialValue);
|
||||
>(getDropdownOptionFromValue(props.initialValue));
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (props.value) {
|
||||
setValue(props.value ? props.value : undefined);
|
||||
setValue(getDropdownOptionFromValue(props.value ? props.value : undefined));
|
||||
}
|
||||
}, [props.value]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user