diff --git a/src/components/common/KriAutoComplete.tsx b/src/components/common/KriAutoComplete.tsx index 1aa29e5..2621a71 100644 --- a/src/components/common/KriAutoComplete.tsx +++ b/src/components/common/KriAutoComplete.tsx @@ -3,14 +3,15 @@ import * as React from 'react' import { cn } from '@/lib/utils' import { MultiSelect } from '@/components/common/multi-select' -import type { MultiSelectOption, MultiSelectRef } from '@/components/common/multi-select' +import type { MultiSelectOption, MultiSelectRef, MultiSelectSearchMatch } from '@/components/common/multi-select' -export type { MultiSelectOption, MultiSelectRef } from '@/components/common/multi-select' +export type { MultiSelectOption, MultiSelectRef, MultiSelectSearchMatch } from '@/components/common/multi-select' export interface KriAutoCompleteBaseProps { items: T[] searchable?: boolean searchMode?: 'filter' | 'inputOnly' + searchMatch?: MultiSelectSearchMatch defaultSearchValue?: string onSearchValueChange?: (value: string) => void placeholder?: string @@ -58,6 +59,7 @@ export function KriMultiSelect({ onChange, searchable = true, searchMode = 'filter', + searchMatch = 'contains', defaultSearchValue = '', onSearchValueChange, maxCount = 1, @@ -100,6 +102,7 @@ export function KriMultiSelect({ badgeLabelClassName={badgeLabelClassName} searchable={searchable} searchMode={searchMode} + searchMatch={searchMatch} defaultSearchValue={defaultSearchValue} onSearchValueChange={onSearchValueChange} maxCount={maxCount} @@ -135,6 +138,7 @@ function KriSingleSelectInner( onChange, searchable = true, searchMode = 'filter', + searchMatch = 'contains', defaultSearchValue = '', onSearchValueChange, placeholder = '옵션을 선택하세요', @@ -216,6 +220,7 @@ function KriSingleSelectInner( badgeLabelClassName={badgeLabelClassName ?? 'min-w-0 flex-1'} searchable={searchable} searchMode={searchMode} + searchMatch={searchMatch} defaultSearchValue={defaultSearchValue} onSearchValueChange={onSearchValueChange} preventDeselect={preventDeselect} diff --git a/src/components/common/multi-select/MultiSelect.tsx b/src/components/common/multi-select/MultiSelect.tsx index 50981de..57dd2e5 100644 --- a/src/components/common/multi-select/MultiSelect.tsx +++ b/src/components/common/multi-select/MultiSelect.tsx @@ -31,6 +31,7 @@ function MultiSelectInner( hideSelectAll = false, searchable = true, searchMode = 'filter', + searchMatch = 'fuzzy', defaultSearchValue = '', onSearchValueChange, emptyIndicator = '검색 결과가 없습니다.', @@ -201,6 +202,7 @@ function MultiSelectInner( selectedValues={selectedValues} searchable={searchable} searchMode={searchMode} + searchMatch={searchMatch} searchValue={searchValue} onSearchValueChange={handleSearchChange} hideSelectAll={hideSelectAll} diff --git a/src/components/common/multi-select/MultiSelectContent.tsx b/src/components/common/multi-select/MultiSelectContent.tsx index 905f117..eddd1eb 100644 --- a/src/components/common/multi-select/MultiSelectContent.tsx +++ b/src/components/common/multi-select/MultiSelectContent.tsx @@ -11,14 +11,19 @@ import { CommandSeparator, } from '@/components/ui/command' import { cn } from '@/lib/utils' -import type { MultiSelectGroup, MultiSelectOption, MultiSelectOptions } from './types' +import type { MultiSelectGroup, MultiSelectOption, MultiSelectOptions, MultiSelectSearchMatch } from './types' import { isGroupedOptions } from './utils' +function containsFilter(value: string, search: string) { + return value.toLowerCase().includes(search.toLowerCase()) ? 1 : 0 +} + interface MultiSelectContentProps { options: MultiSelectOptions selectedValues: string[] searchable: boolean searchMode: 'filter' | 'inputOnly' + searchMatch?: MultiSelectSearchMatch searchValue: string onSearchValueChange: (value: string) => void hideSelectAll: boolean @@ -96,6 +101,7 @@ export function MultiSelectContent({ selectedValues, searchable, searchMode, + searchMatch = 'fuzzy', searchValue, onSearchValueChange, hideSelectAll, @@ -111,7 +117,7 @@ export function MultiSelectContent({ const allSelected = selectableOptions.length > 0 && selectableOptions.every((option) => selectedValues.includes(option.value)) return ( - + {searchable ? ( { export type MultiSelectOptions = MultiSelectOption[] | MultiSelectGroup[] export type MultiSelectSelectionMode = 'single' | 'multiple' +export type MultiSelectSearchMatch = 'fuzzy' | 'contains' export type MultiSelectVariant = 'default' | 'secondary' | 'destructive' | 'inverted' export interface MultiSelectResponsiveSettings { @@ -65,6 +66,7 @@ export interface MultiSelectProps hideSelectAll?: boolean searchable?: boolean searchMode?: 'filter' | 'inputOnly' + searchMatch?: MultiSelectSearchMatch defaultSearchValue?: string onSearchValueChange?: (value: string) => void emptyIndicator?: React.ReactNode