Skip to content

SearchInput

A field for finding things. It carries the magnifier, so people know what it is for before reading, and phones show their search keyboard.

import { SearchInput } from '@sypnia/ui/react'

On this page
  1. Filtering a list
  2. Sizes
  3. With a label, and disabled
  4. When to use it
  5. For everyone
  6. Props

Filtering a list

Type «ord», then something that does not exist: the empty result says what to do next.

Tables

orders1,204 rows
order_items3,811 rows
customers418 rows
products96 rows
refunds23 rows
Code
import { useState } from 'react';
import { Badge, EmptyState, Panel, SearchInput } from '@sypnia/ui/react';

const tables = [['orders', 1204], ['order_items', 3811], ['customers', 418], ['products', 96], ['refunds', 23]] as const;
// Type «ord», then something that does not exist.
export default function FilterAList() {
  const [q, setQ] = useState('');
  const found = tables.filter(([name]) => name.includes(q.trim().toLowerCase()));
  return (
    <Panel title="Tables" actions={<SearchInput size="sm" aria-label="Filter tables" placeholder="Filter tables" value={q} onChange={(e) => setQ(e.target.value)} />}>
      {found.length === 0
        ? <EmptyState compact icon="search" title={`No table is called «${q}»`}>Check the spelling, or clear the filter to see all {tables.length}.</EmptyState>
        : <div className="sy-stack">{found.map(([name, rows]) => (
            <div key={name} className="sy-row sy-row--between"><span className="sy-machine">{name}</span><Badge>{rows.toLocaleString('en')} rows</Badge></div>
          ))}</div>}
    </Panel>
  );
}

Sizes

Small for toolbars, medium for forms, large for a search page.

Code
import { SearchInput } from '@sypnia/ui/react';

// Without a label of its own it is named «Search», in the language of the page.
export default function Sizes() {
  return (
    <div className="sy-cols sy-cols--stack">
      <SearchInput size="sm" placeholder="Search rows" />
      <SearchInput />
      <SearchInput size="lg" placeholder="Search projects, tables and keys" />
    </div>
  );
}

With a label, and disabled

A Field gives it a visible name and help.

By name, email or order number.

Search is off while the logs are being archived.

Code
import { Field, FormGrid, SearchInput } from '@sypnia/ui/react';

export default function InAField() {
  return (
    <FormGrid>
      <Field label="Find a customer" hint="By name, email or order number.">
        <SearchInput placeholder="laura@northwind.io" />
      </Field>
      <Field label="Search the logs" hint="Search is off while the logs are being archived.">
        <SearchInput disabled placeholder="status:500" />
      </Field>
    </FormGrid>
  );
}

When to use it

Use it when

  • Filtering a list or a table that is on screen, as the person types.
  • Searching across the app, where the results appear somewhere else.

Do not use it when

  • The person is entering a value to save: that is an Input.
  • Choosing one option from a list with search: that is a Combobox.
  • The list is short enough to read in full: do not add a filter nobody needs.

For everyone

  • It is a search box for screen readers (type="search"). Escape clears it in most browsers.
  • Without a label of its own it is named «Search», in the language of the page. Inside a Field the visible label names it; in a toolbar give it aria-label («Filter tables»).
  • When nothing matches, say so in words and offer the way back, as in the first example.

Props

SearchInputTypeDefault
machine

Machine text (ids, keys, code): set in the mono face.

boolean
size "sm" | "md" | "lg"
  1. Filtering a list
  2. Sizes
  3. With a label, and disabled
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms