Search

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.

Show Code
1import { Search } from '@devup-ui/components'
2
3export default function Default() {
4    return <Search aria-label="Search" placeholder="Search" />
5}
6
1import { Search } from '@devup-ui/components'
2
3export default function Default() {
4    return <Search aria-label="Search" placeholder="Search" />
5}
6

Next.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.

Show Code
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}
29
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}
29

Nothing 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.

Show Code
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}
23
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}
23

Disabled Use the disabled prop to prevent searching. The clear button is hidden and Escape keeps the query.

Show Code
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}
13
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}
13
API

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.

PropdescriptionTypeDefault
onSearch

Callback with the current query when Enter is pressed (not on the Enter that confirms an IME composition)

(value: string) => void

undefined

icon

Icon on the left side of the input; null hides it

React.ReactNode

magnifier icon

allowClear

Whether a clear button appears when there is a query, and Escape clears it

boolean

true

onClear

Callback when the query is cleared with the clear button or Escape

() => void

undefined

enterKeyHint

Label of the Enter key on virtual keyboards

string

'search'

disabled

Whether the search input is disabled

boolean

false