261020_01_ENH: kri-auto-complete 검색 시 옵션 목록 스크롤 초기화 옵션 추가
This commit is contained in:
@@ -7,6 +7,11 @@ When implementing or changing frontend UI, use this order:
|
||||
3. Otherwise, prefer a suitable shadcn/ui component.
|
||||
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
|
||||
|
||||
Before each related task, read the current contents of every matching reference, even if it was read earlier in the session.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { HTMLAttributes, InputHTMLAttributes } from "react";
|
||||
import { forwardRef } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
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>) {
|
||||
return <div className={cn(className)} {...props} />;
|
||||
}
|
||||
export const CommandList = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
function CommandList({ className, ...props }, ref) {
|
||||
return <div ref={ref} className={cn(className)} {...props} />;
|
||||
},
|
||||
);
|
||||
|
||||
export function CommandEmpty({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={cn(className)} {...props} />;
|
||||
|
||||
@@ -243,6 +243,11 @@ When implementing or changing frontend UI, use this order:
|
||||
3. Otherwise, prefer a suitable shadcn/ui component.
|
||||
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
|
||||
|
||||
Before each related task, read the current contents of every matching reference, even if it was read earlier in the session.
|
||||
|
||||
15
README.md
15
README.md
@@ -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
|
||||
```
|
||||
|
||||
## 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`는 `echarts`, `echarts-for-react` 기반 공통 차트 컴포넌트입니다. 내부적으로 `BaseEChart`를 사용하며, 모든 wrapper는 멀티 시리즈를 지원합니다.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kri-ui-registry",
|
||||
"version": "0.14.0",
|
||||
"version": "0.14.1",
|
||||
"private": true,
|
||||
"description": "KRI internal shadcn UI registry",
|
||||
"scripts": {
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface KriAutoCompleteBaseProps<T> {
|
||||
items: T[]
|
||||
searchable?: boolean
|
||||
searchMode?: 'filter' | 'inputOnly'
|
||||
resetScrollOnSearch?: boolean
|
||||
defaultSearchValue?: string
|
||||
onSearchValueChange?: (value: string) => void
|
||||
placeholder?: string
|
||||
@@ -56,6 +57,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
resetScrollOnSearch = false,
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
maxCount = 1,
|
||||
@@ -96,6 +98,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
badgeClassName={badgeClassName}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
resetScrollOnSearch={resetScrollOnSearch}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
maxCount={maxCount}
|
||||
@@ -131,6 +134,7 @@ function KriSingleSelectInner<T>({
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
resetScrollOnSearch = false,
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
placeholder = 'Select an option',
|
||||
@@ -208,6 +212,7 @@ function KriSingleSelectInner<T>({
|
||||
badgeClassName={badgeClassName}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
resetScrollOnSearch={resetScrollOnSearch}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
preventDeselect={preventDeselect}
|
||||
|
||||
@@ -30,6 +30,7 @@ function MultiSelectInner<T>(
|
||||
hideSelectAll = false,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
resetScrollOnSearch = false,
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
emptyIndicator = '검색 결과가 없습니다.',
|
||||
@@ -199,6 +200,7 @@ function MultiSelectInner<T>(
|
||||
selectedValues={selectedValues}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
resetScrollOnSearch={resetScrollOnSearch}
|
||||
searchValue={searchValue}
|
||||
onSearchValueChange={handleSearchChange}
|
||||
hideSelectAll={hideSelectAll}
|
||||
|
||||
@@ -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 ? (
|
||||
<>
|
||||
|
||||
@@ -64,6 +64,7 @@ export interface MultiSelectProps<T = unknown>
|
||||
hideSelectAll?: boolean
|
||||
searchable?: boolean
|
||||
searchMode?: 'filter' | 'inputOnly'
|
||||
resetScrollOnSearch?: boolean
|
||||
defaultSearchValue?: string
|
||||
onSearchValueChange?: (value: string) => void
|
||||
emptyIndicator?: React.ReactNode
|
||||
|
||||
Reference in New Issue
Block a user