Examples

Basic

Wrap in <search> to expose a search landmark.

Preview
Example.tsx
import { SearchInput } from '@reactloom/ui';

export default function Example() {
  return (
    <search style={{ width: '100%', maxWidth: 360 }}>
      <SearchInput aria-label="Search customers" placeholder="Search customers" defaultValue="Acme" />
    </search>
  );
}

Live filtering

Announce the result count in a status region.

Preview

5 of 5 customers

  • Acme Corporation
  • Globex
  • Initech
  • Umbrella Health
  • Wayne Enterprises
Example.tsx
import { List, SearchInput, Stack, Text } from '@reactloom/ui';
import { useState } from 'react';

const customers = ['Acme Corporation', 'Globex', 'Initech', 'Umbrella Health', 'Wayne Enterprises'];

export default function Example() {
  const [query, setQuery] = useState('');
  const results = customers.filter((c) => c.toLowerCase().includes(query.toLowerCase()));
  return (
    <Stack gap="3" style={{ width: '100%', maxWidth: 360 }}>
      <SearchInput aria-label="Filter customers" placeholder="Filter customers" value={query} onValueChange={setQuery} />
      <Text size="sm" tone="muted" role="status">
        {results.length} of {customers.length} customers
      </Text>
      <List marker="none" spacing="sm">
        {results.map((c) => (
          <li key={c}>{c}</li>
        ))}
      </List>
    </Stack>
  );
}

API reference

SearchInput props
PropTypeDefault
onValueChange
Called on typing and on clear.
(value: string) => void—
onClear
() => void—
clearLabel
string'Clear search'
…
Everything Input accepts (without sections).
InputProps—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

Renders Input, so its hooks apply too.

Slot class names

Add classes to inner parts with classNames (className is shorthand for root): root, label, description, control, input, section, error.

CSS variables

VariableDefault
--pl-input-radiusvar(--pl-radius-md

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-invalid]present when on
[data-radius]none · sm · md · lg · full
[data-readonly]present when on
[data-size]sm · md · lg

Theme tokens it reads

--pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-focus --pl-color-border-input --pl-color-danger-border --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-color-fg-subtle --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-full --pl-radius-lg --pl-radius-md --pl-radius-none --pl-radius-sm --pl-shadow-xs

Accessibility

  • The browser’s own clear button is hidden in favour of a labelled one.
  • Escape clears the value and stops propagation; a second Escape reaches the dialog.
Keyboard interactions
KeyAction
EscapeClear the query
TabReach the clear button

Usage guidelines

Do

  • Announce result counts politely.

Don’t

  • Don’t trigger expensive searches on every keystroke without debouncing.