261020_01_ENH: kri-auto-complete 검색 시 옵션 목록 스크롤 초기화 옵션 추가

This commit is contained in:
2026-10-20 15:00:07 +09:00
parent 4bcc339c51
commit 487302d374
9 changed files with 55 additions and 5 deletions

View File

@@ -7,6 +7,11 @@ When implementing or changing frontend UI, use this order:
3. Otherwise, prefer a suitable shadcn/ui component. 3. Otherwise, prefer a suitable shadcn/ui component.
4. Create a custom component only when the preceding options cannot meet the requirement safely. 4. Create a custom component only when the preceding options cannot meet the requirement safely.
### KriAutoComplete Search Scroll
- `kri-auto-complete` exposes `resetScrollOnSearch?: boolean` on `KriSingleSelect`, `KriMultiSelect`, and `MultiSelect`. It defaults to `false`, preserving existing behavior.
- When enabled, a search value change (including clearing it) resets the option list scroll to the top on the next animation frame in both `filter` and `inputOnly` modes. Async result updates alone do not trigger another reset.
### Required Shared References ### Required Shared References
Before each related task, read the current contents of every matching reference, even if it was read earlier in the session. Before each related task, read the current contents of every matching reference, even if it was read earlier in the session.

View File

@@ -1,4 +1,5 @@
import type { HTMLAttributes, InputHTMLAttributes } from "react"; import type { HTMLAttributes, InputHTMLAttributes } from "react";
import { forwardRef } from "react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
export interface CommandProps extends HTMLAttributes<HTMLDivElement> { export interface CommandProps extends HTMLAttributes<HTMLDivElement> {
@@ -26,9 +27,11 @@ export function CommandInput({ className, onValueChange, onChange, ...props }: C
); );
} }
export function CommandList({ className, ...props }: HTMLAttributes<HTMLDivElement>) { export const CommandList = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
return <div className={cn(className)} {...props} />; function CommandList({ className, ...props }, ref) {
} return <div ref={ref} className={cn(className)} {...props} />;
},
);
export function CommandEmpty({ className, ...props }: HTMLAttributes<HTMLDivElement>) { export function CommandEmpty({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
return <div className={cn(className)} {...props} />; return <div className={cn(className)} {...props} />;

View File

@@ -243,6 +243,11 @@ When implementing or changing frontend UI, use this order:
3. Otherwise, prefer a suitable shadcn/ui component. 3. Otherwise, prefer a suitable shadcn/ui component.
4. Create a custom component only when the preceding options cannot meet the requirement safely. 4. Create a custom component only when the preceding options cannot meet the requirement safely.
### KriAutoComplete Search Scroll
- `kri-auto-complete` exposes `resetScrollOnSearch?: boolean` on `KriSingleSelect`, `KriMultiSelect`, and `MultiSelect`. It defaults to `false`, preserving existing behavior.
- When enabled, a search value change (including clearing it) resets the option list scroll to the top on the next animation frame in both `filter` and `inputOnly` modes. Async result updates alone do not trigger another reset.
### Required Shared References ### Required Shared References
Before each related task, read the current contents of every matching reference, even if it was read earlier in the session. Before each related task, read the current contents of every matching reference, even if it was read earlier in the session.

View File

@@ -61,6 +61,21 @@ npx shadcn@latest add https://ui-registry.kric.com/r/kri-layout.json
npx shadcn@latest add https://ui-registry.kric.com/r/kri-dialog.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-dialog.json
``` ```
## KriAutoComplete 검색 스크롤
`kri-auto-complete`의 `KriSingleSelect`, `KriMultiSelect`와 내부 `MultiSelect`는 `resetScrollOnSearch?: boolean`을 지원합니다. 기본값은 `false`로 기존 동작을 유지합니다.
`true`이면 검색어 변경(삭제 포함) 후 다음 프레임에 옵션 목록의 스크롤을 맨 위로 이동합니다. `searchMode="filter"`와 `searchMode="inputOnly"` 모두 적용되며, 비동기 결과 도착만으로 다시 초기화하지는 않습니다.
```tsx
<KriSingleSelect
items={items}
value={value}
onChange={setValue}
resetScrollOnSearch
/>
```
## KRI Chart ## KRI Chart
`kri-chart`는 `echarts`, `echarts-for-react` 기반 공통 차트 컴포넌트입니다. 내부적으로 `BaseEChart`를 사용하며, 모든 wrapper는 멀티 시리즈를 지원합니다. `kri-chart`는 `echarts`, `echarts-for-react` 기반 공통 차트 컴포넌트입니다. 내부적으로 `BaseEChart`를 사용하며, 모든 wrapper는 멀티 시리즈를 지원합니다.

View File

@@ -1,6 +1,6 @@
{ {
"name": "kri-ui-registry", "name": "kri-ui-registry",
"version": "0.14.0", "version": "0.14.1",
"private": true, "private": true,
"description": "KRI internal shadcn UI registry", "description": "KRI internal shadcn UI registry",
"scripts": { "scripts": {

View File

@@ -11,6 +11,7 @@ export interface KriAutoCompleteBaseProps<T> {
items: T[] items: T[]
searchable?: boolean searchable?: boolean
searchMode?: 'filter' | 'inputOnly' searchMode?: 'filter' | 'inputOnly'
resetScrollOnSearch?: boolean
defaultSearchValue?: string defaultSearchValue?: string
onSearchValueChange?: (value: string) => void onSearchValueChange?: (value: string) => void
placeholder?: string placeholder?: string
@@ -56,6 +57,7 @@ export function KriMultiSelect<T = unknown>({
onChange, onChange,
searchable = true, searchable = true,
searchMode = 'filter', searchMode = 'filter',
resetScrollOnSearch = false,
defaultSearchValue = '', defaultSearchValue = '',
onSearchValueChange, onSearchValueChange,
maxCount = 1, maxCount = 1,
@@ -96,6 +98,7 @@ export function KriMultiSelect<T = unknown>({
badgeClassName={badgeClassName} badgeClassName={badgeClassName}
searchable={searchable} searchable={searchable}
searchMode={searchMode} searchMode={searchMode}
resetScrollOnSearch={resetScrollOnSearch}
defaultSearchValue={defaultSearchValue} defaultSearchValue={defaultSearchValue}
onSearchValueChange={onSearchValueChange} onSearchValueChange={onSearchValueChange}
maxCount={maxCount} maxCount={maxCount}
@@ -131,6 +134,7 @@ function KriSingleSelectInner<T>({
onChange, onChange,
searchable = true, searchable = true,
searchMode = 'filter', searchMode = 'filter',
resetScrollOnSearch = false,
defaultSearchValue = '', defaultSearchValue = '',
onSearchValueChange, onSearchValueChange,
placeholder = 'Select an option', placeholder = 'Select an option',
@@ -208,6 +212,7 @@ function KriSingleSelectInner<T>({
badgeClassName={badgeClassName} badgeClassName={badgeClassName}
searchable={searchable} searchable={searchable}
searchMode={searchMode} searchMode={searchMode}
resetScrollOnSearch={resetScrollOnSearch}
defaultSearchValue={defaultSearchValue} defaultSearchValue={defaultSearchValue}
onSearchValueChange={onSearchValueChange} onSearchValueChange={onSearchValueChange}
preventDeselect={preventDeselect} preventDeselect={preventDeselect}

View File

@@ -30,6 +30,7 @@ function MultiSelectInner<T>(
hideSelectAll = false, hideSelectAll = false,
searchable = true, searchable = true,
searchMode = 'filter', searchMode = 'filter',
resetScrollOnSearch = false,
defaultSearchValue = '', defaultSearchValue = '',
onSearchValueChange, onSearchValueChange,
emptyIndicator = '검색 결과가 없습니다.', emptyIndicator = '검색 결과가 없습니다.',
@@ -199,6 +200,7 @@ function MultiSelectInner<T>(
selectedValues={selectedValues} selectedValues={selectedValues}
searchable={searchable} searchable={searchable}
searchMode={searchMode} searchMode={searchMode}
resetScrollOnSearch={resetScrollOnSearch}
searchValue={searchValue} searchValue={searchValue}
onSearchValueChange={handleSearchChange} onSearchValueChange={handleSearchChange}
hideSelectAll={hideSelectAll} hideSelectAll={hideSelectAll}

View File

@@ -1,5 +1,6 @@
'use client' 'use client'
import * as React from 'react'
import { CheckIcon } from 'lucide-react' import { CheckIcon } from 'lucide-react'
import { import {
Command, Command,
@@ -20,6 +21,7 @@ interface MultiSelectContentProps<T> {
searchable: boolean searchable: boolean
searchMode: 'filter' | 'inputOnly' searchMode: 'filter' | 'inputOnly'
searchValue: string searchValue: string
resetScrollOnSearch?: boolean
onSearchValueChange: (value: string) => void onSearchValueChange: (value: string) => void
hideSelectAll: boolean hideSelectAll: boolean
hideOptionCheck: boolean hideOptionCheck: boolean
@@ -97,6 +99,7 @@ export function MultiSelectContent<T>({
searchable, searchable,
searchMode, searchMode,
searchValue, searchValue,
resetScrollOnSearch = false,
onSearchValueChange, onSearchValueChange,
hideSelectAll, hideSelectAll,
hideOptionCheck, hideOptionCheck,
@@ -105,6 +108,17 @@ export function MultiSelectContent<T>({
onToggleOption, onToggleOption,
onToggleAll, onToggleAll,
}: MultiSelectContentProps<T>) { }: 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 grouped = isGroupedOptions(options)
const flatOptions = grouped ? options.flatMap((group) => group.options) : options const flatOptions = grouped ? options.flatMap((group) => group.options) : options
const selectableOptions = flatOptions.filter((option) => !option.disabled) const selectableOptions = flatOptions.filter((option) => !option.disabled)
@@ -119,7 +133,7 @@ export function MultiSelectContent<T>({
placeholder="검색..." placeholder="검색..."
/> />
) : null} ) : null}
<CommandList> <CommandList ref={listRef}>
<CommandEmpty>{emptyIndicator}</CommandEmpty> <CommandEmpty>{emptyIndicator}</CommandEmpty>
{selectionMode === 'multiple' && !hideSelectAll && selectableOptions.length > 0 ? ( {selectionMode === 'multiple' && !hideSelectAll && selectableOptions.length > 0 ? (
<> <>

View File

@@ -64,6 +64,7 @@ export interface MultiSelectProps<T = unknown>
hideSelectAll?: boolean hideSelectAll?: boolean
searchable?: boolean searchable?: boolean
searchMode?: 'filter' | 'inputOnly' searchMode?: 'filter' | 'inputOnly'
resetScrollOnSearch?: boolean
defaultSearchValue?: string defaultSearchValue?: string
onSearchValueChange?: (value: string) => void onSearchValueChange?: (value: string) => void
emptyIndicator?: React.ReactNode emptyIndicator?: React.ReactNode