Search
Search 컴포넌트는 사용자가 검색어를 입력해 콘텐츠를 필터링하거나 Enter로 검색을 실행할 수 있는 검색 입력 필드입니다.
예제
Default
A search input with a magnifier icon. Name it with aria-label (or a <label>) since it usually has no visible label. A clear button appears once there is a query, and Escape clears it too.
1import { Search } from '@devup-ui/components'
2
3export default function Default() {
4 return <Search aria-label="Search" placeholder="Search" />
5}
61import { Search } from '@devup-ui/components'
2
3export default function Default() {
4 return <Search aria-label="Search" placeholder="Search" />
5}
6Next.js, Vite, Rsbuild, Webpack, Bun
Filter
Use onChange to filter a list while the user types. Clearing the query with the clear button or Escape also fires onChange, so the list resets.
1'use client'
2
3import { Search } from '@devup-ui/components'
4import { Text, VStack } from '@devup-ui/react'
5import { useState } from 'react'
6
7const FRAMEWORKS = ['Next.js', 'Vite', 'Rsbuild', 'Webpack', 'Bun']
8
9export default function Filter() {
10 const [query, setQuery] = useState('')
11 const matches = FRAMEWORKS.filter((name) =>
12 name.toLowerCase().includes(query.trim().toLowerCase()),
13 )
14
15 return (
16 <VStack gap="12px">
17 <Search
18 aria-label="Filter frameworks"
19 onChange={(e) => setQuery(e.target.value)}
20 placeholder="Filter frameworks"
21 value={query}
22 />
23 <Text as="p" color="$text" m="0" typography="bodyReg">
24 {matches.length ? matches.join(', ') : 'No match'}
25 </Text>
26 </VStack>
27 )
28}
291'use client'
2
3import { Search } from '@devup-ui/components'
4import { Text, VStack } from '@devup-ui/react'
5import { useState } from 'react'
6
7const FRAMEWORKS = ['Next.js', 'Vite', 'Rsbuild', 'Webpack', 'Bun']
8
9export default function Filter() {
10 const [query, setQuery] = useState('')
11 const matches = FRAMEWORKS.filter((name) =>
12 name.toLowerCase().includes(query.trim().toLowerCase()),
13 )
14
15 return (
16 <VStack gap="12px">
17 <Search
18 aria-label="Filter frameworks"
19 onChange={(e) => setQuery(e.target.value)}
20 placeholder="Filter frameworks"
21 value={query}
22 />
23 <Text as="p" color="$text" m="0" typography="bodyReg">
24 {matches.length ? matches.join(', ') : 'No match'}
25 </Text>
26 </VStack>
27 )
28}
29Nothing searched yet
On Search
Use onSearch to run a search when the user presses Enter. It receives the current query, and is not called on the Enter that confirms an IME composition.
1'use client'
2
3import { Search } from '@devup-ui/components'
4import { Text, VStack } from '@devup-ui/react'
5import { useState } from 'react'
6
7export default function OnSearch() {
8 const [submitted, setSubmitted] = useState('')
9
10 return (
11 <VStack gap="12px">
12 <Search
13 aria-label="Search and press Enter"
14 onSearch={setSubmitted}
15 placeholder="Type and press Enter"
16 />
17 <Text as="p" color="$text" m="0" typography="bodyReg">
18 {submitted ? `Searched for "${submitted}"` : 'Nothing searched yet'}
19 </Text>
20 </VStack>
21 )
22}
231'use client'
2
3import { Search } from '@devup-ui/components'
4import { Text, VStack } from '@devup-ui/react'
5import { useState } from 'react'
6
7export default function OnSearch() {
8 const [submitted, setSubmitted] = useState('')
9
10 return (
11 <VStack gap="12px">
12 <Search
13 aria-label="Search and press Enter"
14 onSearch={setSubmitted}
15 placeholder="Type and press Enter"
16 />
17 <Text as="p" color="$text" m="0" typography="bodyReg">
18 {submitted ? `Searched for "${submitted}"` : 'Nothing searched yet'}
19 </Text>
20 </VStack>
21 )
22}
23Disabled
Use the disabled prop to prevent searching. The clear button is hidden and Escape keeps the query.
1import { Search } from '@devup-ui/components'
2
3export default function Disabled() {
4 return (
5 <Search
6 aria-label="Search"
7 defaultValue="devup"
8 disabled
9 placeholder="Search"
10 />
11 )
12}
131import { Search } from '@devup-ui/components'
2
3export default function Disabled() {
4 return (
5 <Search
6 aria-label="Search"
7 defaultValue="devup"
8 disabled
9 placeholder="Search"
10 />
11 )
12}
13API
Search props는 Input props(type 제외)를 확장하므로 value, defaultValue, onChange, error, errorMessage, classNames, colors가 Textbox에서와 같이 동작합니다. <input type="search">를 렌더링하므로 보조 기술은 이를 검색 상자로 안내합니다.
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| onSearch | Enter를 누르면 현재 검색어와 함께 호출되는 콜백(IME 조합을 확정하는 Enter에서는 호출되지 않음) |
|
|
| icon | 입력 필드 왼쪽의 아이콘. |
| 돋보기 아이콘 |
| allowClear | 검색어가 있을 때 지우기 버튼을 표시하고 Escape로 지울 수 있게 할지 여부 |
|
|
| onClear | 지우기 버튼이나 Escape로 검색어를 지웠을 때 호출되는 콜백 |
|
|
| enterKeyHint | 가상 키보드의 Enter 키 레이블 |
|
|
| disabled | 검색 입력 필드의 비활성화 여부 |
|
|