🐛 fix: on reset error when value is undefined

This commit is contained in:
Wahyu Kurniawan 2024-03-06 11:23:25 +07:00
parent 462d247a86
commit b6e02fb19d
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33

View File

@ -167,7 +167,8 @@ export const Select = ({
} }
}, [dropdownOpen]); // Re-calculate whenever the dropdown is opened }, [dropdownOpen]); // Re-calculate whenever the dropdown is opened
const handleSelectedItemChange = (selectedItem: SelectOption | null) => { const handleSelectedItemChange = (selectedItem: SelectOption | undefined) => {
if (!selectedItem) return;
setSelectedItem(selectedItem); setSelectedItem(selectedItem);
setInputValue(selectedItem ? selectedItem.label : ''); setInputValue(selectedItem ? selectedItem.label : '');
onChange?.(selectedItem as SelectOption); onChange?.(selectedItem as SelectOption);
@ -185,7 +186,7 @@ export const Select = ({
onSelectedItemsChange: multiple onSelectedItemsChange: multiple
? undefined ? undefined
: ({ selectedItems }) => { : ({ selectedItems }) => {
handleSelectedItemChange(selectedItems?.[0] || null); handleSelectedItemChange(selectedItems?.[0]);
}, },
}); });