fix(combobox): allow for null emptyFilterKey and fix setSelection

This commit is contained in:
Paul Chavard 2024-07-09 16:16:07 +02:00
parent 6b5aa697cf
commit 9468471164
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View file

@ -52,7 +52,7 @@ export function useSingleList({
}: {
defaultItems?: Item[];
defaultSelectedKey?: string | null;
emptyFilterKey?: string;
emptyFilterKey?: string | null;
onChange?: (item: Item | null) => void;
}) {
const [selectedKey, setSelectedKey] = useState(defaultSelectedKey);
@ -85,8 +85,8 @@ export function useSingleList({
const initialSelectedKeyRef = useRef(defaultSelectedKey);
const setSelection = useEvent((key?: string | null) => {
const inputValue = defaultSelectedKey
? items.find((item) => item.value == defaultSelectedKey)?.label
const inputValue = key
? items.find((item) => item.value == key)?.label
: '';
setSelectedKey(key);
setInputValue(inputValue ?? '');

View file

@ -46,7 +46,7 @@ export const SingleComboBoxProps = s.assign(
s.partial(
s.object({
selectedKey: s.nullable(s.string()),
emptyFilterKey: s.string()
emptyFilterKey: s.nullable(s.string())
})
)
);