From 79238a8a4168107e64df4b67e92eec6069bffef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=AA=20Boaventura?= Date: Mon, 22 Apr 2024 16:26:56 -0300 Subject: [PATCH] fix: Fix tag multi select (#585) --- src/components/TagMultiSelect.tsx | 35 ++++++++++++++++++-------- src/index.ts | 1 + src/stories/ComboBox.stories.tsx | 3 +++ src/stories/TagMultiselectTemplate.tsx | 3 +++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/components/TagMultiSelect.tsx b/src/components/TagMultiSelect.tsx index 627ce4f1..64116807 100644 --- a/src/components/TagMultiSelect.tsx +++ b/src/components/TagMultiSelect.tsx @@ -21,25 +21,33 @@ export type MultiSelectTag = { const matchOptions = [ { label: 'All', value: 'AND' }, { label: 'Any', value: 'OR' }, -] +] as const -export function TagMultiSelect({ - options, - loading, - onSelectedTagsChange, - onFilterChange, -}: { +type TagMultiSelectProps = { options: string[] loading: boolean + selectedMatchType?: 'AND' | 'OR' onSelectedTagsChange?: (keys: Set) => void onFilterChange?: (value: string) => void -}) { + onChangeMatchType?: (value: 'AND' | 'OR') => void +} + +function TagMultiSelect({ + options, + loading, + selectedMatchType, + onSelectedTagsChange, + onFilterChange, + onChangeMatchType, +}: TagMultiSelectProps) { const theme = useTheme() const [selectedTagKeys, setSelectedTagKeys] = useState(new Set()) const selectedTagArr = useMemo(() => [...selectedTagKeys], [selectedTagKeys]) const [inputValue, setInputValue] = useState('') const [isOpen, setIsOpen] = useState(false) - const [searchLogic, setSearchLogic] = useState(matchOptions[0].value) + const [searchLogic, setSearchLogic] = useState( + selectedMatchType || matchOptions[0].value + ) const onSelectionChange: ComponentProps< typeof ComboBox @@ -72,8 +80,9 @@ export function TagMultiSelect({