261020_01_ENH: kri-auto-complete 검색 시 옵션 목록 스크롤 초기화 옵션 추가
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import { CheckIcon } from 'lucide-react'
|
||||
import {
|
||||
Command,
|
||||
@@ -20,6 +21,7 @@ interface MultiSelectContentProps<T> {
|
||||
searchable: boolean
|
||||
searchMode: 'filter' | 'inputOnly'
|
||||
searchValue: string
|
||||
resetScrollOnSearch?: boolean
|
||||
onSearchValueChange: (value: string) => void
|
||||
hideSelectAll: boolean
|
||||
hideOptionCheck: boolean
|
||||
@@ -97,6 +99,7 @@ export function MultiSelectContent<T>({
|
||||
searchable,
|
||||
searchMode,
|
||||
searchValue,
|
||||
resetScrollOnSearch = false,
|
||||
onSearchValueChange,
|
||||
hideSelectAll,
|
||||
hideOptionCheck,
|
||||
@@ -105,6 +108,17 @@ export function MultiSelectContent<T>({
|
||||
onToggleOption,
|
||||
onToggleAll,
|
||||
}: MultiSelectContentProps<T>) {
|
||||
const listRef = React.useRef<HTMLDivElement>(null)
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!resetScrollOnSearch) return
|
||||
|
||||
const frame = requestAnimationFrame(() => {
|
||||
if (listRef.current) listRef.current.scrollTop = 0
|
||||
})
|
||||
return () => cancelAnimationFrame(frame)
|
||||
}, [resetScrollOnSearch, searchValue])
|
||||
|
||||
const grouped = isGroupedOptions(options)
|
||||
const flatOptions = grouped ? options.flatMap((group) => group.options) : options
|
||||
const selectableOptions = flatOptions.filter((option) => !option.disabled)
|
||||
@@ -119,7 +133,7 @@ export function MultiSelectContent<T>({
|
||||
placeholder="검색..."
|
||||
/>
|
||||
) : null}
|
||||
<CommandList>
|
||||
<CommandList ref={listRef}>
|
||||
<CommandEmpty>{emptyIndicator}</CommandEmpty>
|
||||
{selectionMode === 'multiple' && !hideSelectAll && selectableOptions.length > 0 ? (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user