Krizaka
Documentation

Search field

A search box: a clear button, a global ⌘K / Ctrl+K shortcut, a debounced onSearch, Enter to submit, and suggestions with the keyboard.

Web + MobileBetaForms

Web and mobile — the same component for React and React Native. Beta: its API may still change in a minor version.

When to use

  • At the top of a list or a page to find by words: videos, creators, jobs, users.
  • With shortcut for the site's global search, reachable from anywhere with ⌘K.
  • With suggestions for recent searches or completions under the field.

When not to use

  • To choose a value from a list (the result is the value, not a search): a combobox.Use instead: Combobox
  • For a palette of commands and destinations: the command palette.Use instead: Command

Installation

Install

npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { SearchField } from "@krizaka/ui/search-field";

Examples

Global search

The site's search with its ⌘K shortcut, submitting to a results page.

Recent searches

Suggestions under the field, walked with the arrows.

In a toolbar

size="sm", filtering a list as you type.

  • Flux 1.1
  • Whisper large
  • XTTS v2
  • Llama 3.3
  • Qwen 2.5

Props

A search box: clear, shortcut, debounced search, submit on Enter, suggestions with the keyboard.

PropTypeDefaultDescription
labelrequiredstring—The accessible name of the input ("Search videos"), passed translated.
clearLabelstringClear searchThe clear button's name ("Clear search"), passed translated.
debouncenumber250The pause, in ms, before onSearch. Default 250.
defaultValuestring—The query at first, uncontrolled.
landmarkbooleantrueWraps the field in a role="search" landmark (default) — false inside a form that already is one.
onSearch((query: string) => void)—Called with the query once typing pauses (debounce ms): fetch the results here.
onSubmit((query: string) => void)—Called on Enter (no suggestion active) with the query: go to the results page.
onSuggestionSelect((suggestion: SearchSuggestion) => void)—Called with a suggestion picked (Enter on it, or a click).
onValueChange((query: string) => void)—Called on every key with the query.
shortcutstring | falsefalseThe global key that focuses the field with ⌘ / Ctrl ("k"), or false for none. Default false.
size"sm" | "md"—md (default) · sm.
suggestionsreadonly SearchSuggestion[]—Suggestions under the field (recent searches, completions).
suggestionsLabelstring—A title above the suggestions ("Recent searches").
valuestring—The query (controlled).

Accessibility

  • An input type="search" named by label, inside a search landmark (landmark={false} inside a form that is one).
  • With suggestions it follows the combobox pattern (aria-activedescendant, a listbox).
  • The clear button is named by clearLabel; the shortcut's keys are decorative (aria-hidden).

Keyboard

KeysAction
⌘ K / Ctrl KFocus the field from anywhere (with shortcut="k").
EnterSubmit the query, or pick the active suggestion.
EscClose the suggestions, then clear the query.
Arrow Down / Arrow UpMove through the suggestions.

Best practices

  • Name it by what it searches (“Search videos”), and say it in the placeholder too.
  • Fetch in onSearch (debounced), navigate in onSubmit; keep the query in the address.
  • Show the shortcut only for the site's main search: one ⌘K per page.

Generated from the code of @krizaka/ui 2.4.0: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page