Search
Search component is a search input that lets users type a query to filter content or run a search on Enter.
Examples
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 extend the Input props (except type), so value, defaultValue, onChange, error, errorMessage, classNames and colors work as they do on Textbox. It renders an <input type="search">, which assistive technology announces as a search box.
| Prop | description | Type | Default |
|---|---|---|---|
| onSearch | Callback with the current query when Enter is pressed (not on the Enter that confirms an IME composition) |
|
|
| icon | Icon on the left side of the input; |
| magnifier icon |
| allowClear | Whether a clear button appears when there is a query, and Escape clears it |
|
|
| onClear | Callback when the query is cleared with the clear button or Escape |
|
|
| enterKeyHint | Label of the Enter key on virtual keyboards |
|
|
| disabled | Whether the search input is disabled |
|
|