Merge pull request #10592 from tchak/fix-combobox
fix(combobox): allow for null emptyFilterKey and fix setSelection
This commit is contained in:
commit
0cf153dd20
2 changed files with 4 additions and 4 deletions
|
@ -52,7 +52,7 @@ export function useSingleList({
|
||||||
}: {
|
}: {
|
||||||
defaultItems?: Item[];
|
defaultItems?: Item[];
|
||||||
defaultSelectedKey?: string | null;
|
defaultSelectedKey?: string | null;
|
||||||
emptyFilterKey?: string;
|
emptyFilterKey?: string | null;
|
||||||
onChange?: (item: Item | null) => void;
|
onChange?: (item: Item | null) => void;
|
||||||
}) {
|
}) {
|
||||||
const [selectedKey, setSelectedKey] = useState(defaultSelectedKey);
|
const [selectedKey, setSelectedKey] = useState(defaultSelectedKey);
|
||||||
|
@ -85,8 +85,8 @@ export function useSingleList({
|
||||||
const initialSelectedKeyRef = useRef(defaultSelectedKey);
|
const initialSelectedKeyRef = useRef(defaultSelectedKey);
|
||||||
|
|
||||||
const setSelection = useEvent((key?: string | null) => {
|
const setSelection = useEvent((key?: string | null) => {
|
||||||
const inputValue = defaultSelectedKey
|
const inputValue = key
|
||||||
? items.find((item) => item.value == defaultSelectedKey)?.label
|
? items.find((item) => item.value == key)?.label
|
||||||
: '';
|
: '';
|
||||||
setSelectedKey(key);
|
setSelectedKey(key);
|
||||||
setInputValue(inputValue ?? '');
|
setInputValue(inputValue ?? '');
|
||||||
|
|
|
@ -46,7 +46,7 @@ export const SingleComboBoxProps = s.assign(
|
||||||
s.partial(
|
s.partial(
|
||||||
s.object({
|
s.object({
|
||||||
selectedKey: s.nullable(s.string()),
|
selectedKey: s.nullable(s.string()),
|
||||||
emptyFilterKey: s.string()
|
emptyFilterKey: s.nullable(s.string())
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue