261023_03_ENH: 자동완성 검색 일치 방식(fuzzy/contains) 옵션 추가

This commit is contained in:
2026-10-23 15:15:34 +09:00
parent 7b57ff2c5f
commit bffd953343
11 changed files with 70 additions and 8 deletions

View File

@@ -13,14 +13,26 @@ import {
} from '@/components/ui/command'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
import { cn } from '@/lib/utils'
import type { MultiSelectGroup, MultiSelectOption, MultiSelectOptionTooltip, MultiSelectOptions } from './types'
import type {
MultiSelectGroup,
MultiSelectOption,
MultiSelectOptionTooltip,
MultiSelectOptions,
MultiSelectSearchMatch,
} from './types'
import { isGroupedOptions } from './utils'
// Case-insensitive substring match; equal scores keep the original option order.
function containsFilter(value: string, search: string) {
return value.toLowerCase().includes(search.toLowerCase()) ? 1 : 0
}
interface MultiSelectContentProps<T> {
options: MultiSelectOptions<T>
selectedValues: string[]
searchable: boolean
searchMode: 'filter' | 'inputOnly'
searchMatch?: MultiSelectSearchMatch
searchValue: string
resetScrollOnSearch?: boolean
onSearchValueChange: (value: string) => void
@@ -134,6 +146,7 @@ export function MultiSelectContent<T>({
selectedValues,
searchable,
searchMode,
searchMatch = 'fuzzy',
searchValue,
resetScrollOnSearch = false,
onSearchValueChange,
@@ -164,7 +177,10 @@ export function MultiSelectContent<T>({
const tooltip = optionTooltip ? { mode: optionTooltip, className: optionTooltipClassName } : undefined
const content = (
<Command shouldFilter={searchMode === 'filter'}>
<Command
shouldFilter={searchMode === 'filter'}
filter={searchMatch === 'contains' ? containsFilter : undefined}
>
{searchable ? (
<CommandInput
value={searchValue}