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 + MobileBêtaFormulaires

Web et mobile — le même composant pour React et React Native. Bêta : son API peut encore changer à une version mineure.

Quand l’utiliser

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

Quand ne pas l’utiliser

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

Installation

Installer

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

Styles

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

Importer

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

Exemples

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.

PropTypeDéfautDescription
labelrequisstring—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).

Accessibilité

  • 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).

Clavier

TouchesAction
⌘ 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.

Bonnes pratiques

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

Générée depuis le code de @krizaka/ui 2.4.0 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page