From 94684711646c78225447f5588858a53eca50002c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 9 Jul 2024 16:16:07 +0200 Subject: [PATCH] fix(combobox): allow for null emptyFilterKey and fix setSelection --- app/javascript/components/react-aria/hooks.ts | 6 +++--- app/javascript/components/react-aria/props.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/javascript/components/react-aria/hooks.ts b/app/javascript/components/react-aria/hooks.ts index 200ba16d7..e00bff289 100644 --- a/app/javascript/components/react-aria/hooks.ts +++ b/app/javascript/components/react-aria/hooks.ts @@ -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 ?? ''); diff --git a/app/javascript/components/react-aria/props.ts b/app/javascript/components/react-aria/props.ts index 835b086ea..4932551c5 100644 --- a/app/javascript/components/react-aria/props.ts +++ b/app/javascript/components/react-aria/props.ts @@ -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()) }) ) );