Skip to content

Commit

Permalink
fix: Fix tag multi select (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
renemennab committed Apr 22, 2024
1 parent 0443b7a commit 79238a8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/components/TagMultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key>) => 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<Key>())
const selectedTagArr = useMemo(() => [...selectedTagKeys], [selectedTagKeys])
const [inputValue, setInputValue] = useState('')
const [isOpen, setIsOpen] = useState(false)
const [searchLogic, setSearchLogic] = useState<string>(matchOptions[0].value)
const [searchLogic, setSearchLogic] = useState<string>(
selectedMatchType || matchOptions[0].value
)

const onSelectionChange: ComponentProps<
typeof ComboBox
Expand Down Expand Up @@ -72,8 +80,9 @@ export function TagMultiSelect({
<Select
label="Pick search logic"
selectedKey={searchLogic}
onSelectionChange={(key: string) => {
setSearchLogic(key)
onSelectionChange={(value: 'AND' | 'OR') => {
setSearchLogic(value)
onChangeMatchType?.(value)
}}
defaultOpen={false}
triggerButton={
Expand Down Expand Up @@ -128,6 +137,7 @@ export function TagMultiSelect({
allowsEmptyCollection
loading={loading}
containerProps={{ style: { flexGrow: 1 } }}
showArrow={false}
>
{options
.map((tagStr) => {
Expand Down Expand Up @@ -156,3 +166,6 @@ export function TagMultiSelect({
</Flex>
)
}

export type { TagMultiSelectProps }
export { TagMultiSelect }
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export type {
export { default as LoadingSpinner } from './components/LoadingSpinner'
export { default as LoopingLogo } from './components/LoopingLogo'
export { ComboBox } from './components/ComboBox'
export type { TagMultiSelectProps } from './components/TagMultiSelect'
export { TagMultiSelect } from './components/TagMultiSelect'
export { Toast, GraphQLToast } from './components/Toast'
export { default as WrapWithIf } from './components/WrapWithIf'
Expand Down
3 changes: 3 additions & 0 deletions src/stories/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,7 @@ TagMultiSelect.args = {
onFilterChange: (filter: string) => {
console.log('Filter:', filter)
},
onChangeMatchType: (matchType: 'AND' | 'OR') => {
console.log('Match type: ', matchType)
},
}
3 changes: 3 additions & 0 deletions src/stories/TagMultiselectTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export default function TagMultiSelectTemplate({
width,
onSelectedTagsChange,
onFilterChange,
onChangeMatchType,
}: {
loading: boolean
options: string[]
width: number
onSelectedTagsChange?: (keys: Set<Key>) => void
onFilterChange?: (value: string) => void
onChangeMatchType?: (value: 'AND' | 'OR') => void
}) {
return (
<div style={{ width: `${width}%` }}>
Expand All @@ -22,6 +24,7 @@ export default function TagMultiSelectTemplate({
options={options}
onSelectedTagsChange={onSelectedTagsChange}
onFilterChange={onFilterChange}
onChangeMatchType={onChangeMatchType}
/>
</div>
)
Expand Down

0 comments on commit 79238a8

Please sign in to comment.