bun add @karrotmarket/react-monochrome-icon @seed-design/react
아래 코드를 복사 후 붙여넣고 사용하세요
/** * @file ui:search-input * @requires @seed-design/react@^3.1.0 * @requires @seed-design/css@^3.1.0 **/"use client";import { IconXmarkCircleFill } from "@karrotmarket/react-monochrome-icon"; // "@daangn/react-monochrome-icon"과 동일합니다.import { Icon, SearchInput as SeedSearchInput } from "@seed-design/react";import * as React from "react";export interface SearchInputProps extends Omit<SeedSearchInput.RootProps, "children" | "asChild" | "aria-label"> { placeholder?: string; /** * The accessible name of the input. * @default "검색" */ "aria-label"?: string; /** * The accessible name of the clear button. * @default "지우기" */ clearButtonLabel?: string; /** * Props for the input element, e.g. `maxLength` or `autoFocus`. * Set `disabled` and `readOnly` on `SearchInput` itself, so the clear button follows them. */ inputProps?: Omit<SeedSearchInput.InputProps, "disabled" | "readOnly">;}/** * @see https://seed-design.io/react/components/search-input */export const SearchInput = React.forwardRef<HTMLInputElement, SearchInputProps>( ( { placeholder, "aria-label": ariaLabel = "검색", clearButtonLabel = "지우기", inputProps, ...otherProps }, ref, ) => { return ( <SeedSearchInput.Root {...otherProps}> {/* You may implement your own i18n for the labels */} <SeedSearchInput.Input ref={ref} aria-label={ariaLabel} placeholder={placeholder} {...inputProps} /> <SeedSearchInput.ClearButton aria-label={clearButtonLabel}> <Icon svg={<IconXmarkCircleFill />} /> </SeedSearchInput.ClearButton> </SeedSearchInput.Root> ); },);SearchInput.displayName = "SearchInput";/** * This file is a snippet from SEED Design, helping you get started quickly with @seed-design/* packages. * You can extend this snippet however you want. */
입력의 접근성 레이블은 aria-label(기본값 "검색"), Clear 버튼의 레이블은 clearButtonLabel(기본값 "지우기")로 바꿀 수 있습니다. maxLength, autoFocus처럼 입력 요소에 넘길 속성은 inputProps로 전달하세요. ref는 입력 요소를 가리킵니다.
SearchInput.Root는 role="search"를 가지며, 입력은 type="search"와 enterKeyHint="search"로 렌더링됩니다.
화면에 보이는 레이블이 없으므로 입력과 Clear 버튼에 접근성 레이블이 필요합니다. 직접 조합할 때 SearchInput.Input이나 SearchInput.ClearButton에 aria-label 또는 aria-labelledby가 없으면 개발 콘솔에 경고가 출력됩니다.
콘텐츠를 누르거나 스크롤할 때 키보드를 내리는 동작은 Search Input이 아닌 화면이 담당합니다. Search Bar 예제를 참고하세요.