component
SearchField
Search above a list: a 40px field with the search icon, Input's colours and focus ring, and a clear button once there's something in it.
Try it
Every variant
Default · Not filledDefault · FilledDisabled · Not filledHover, press or tab to one to see the other 2 states.
import { SearchField } from 'rost/components/search-field/SearchField'
<SearchField
label="Search invoices"
placeholder="Search invoices"
value={query}
onValueChange={setQuery}
/> src/components/search-field/SearchField.tsx
import { useRef, useState, type InputHTMLAttributes } from 'react'
import './search-field.css'
export interface SearchFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'value' | 'defaultValue' | 'children'> {
/** What it searches, for screen readers: Search invoices. */
readonly label: string
/** What's typed. Controlled: pair it with `onValueChange`. */
readonly value?: string
readonly defaultValue?: string
/** Called with what's typed each time it changes, and with '' when it's cleared. */
readonly onValueChange?: (value: string) => void
}
const b = 'rost-search-field'
/**
* Search above a list. A real `<input type="search">` in a `role="search"`
* box, with a clear button once something's typed.
* Built from contracts/search-field.contract.yaml.
*/
export function SearchField({ label, value, defaultValue = '', onValueChange, onChange, placeholder = 'Search', disabled, className, style, ...rest }: SearchFieldProps) {
const [own, setOwn] = useState(defaultValue)
const text = value ?? own
const input = useRef<HTMLInputElement>(null)
const set = (next: string) => {
if (value === undefined) setOwn(next)
onValueChange?.(next)
}
const filled = text !== ''
return (
<div
role="search"
className={[b, filled && `${b}--filled`, className].filter(Boolean).join(' ')}
style={style}
// A press anywhere in the box puts the caret in the field.
onMouseDown={(e) => { if (e.target === e.currentTarget) { e.preventDefault(); input.current?.focus() } }}
>
<span className={`${b}__icon`} aria-hidden="true" />
<input
ref={input}
type="search"
className={`${b}__input`}
aria-label={label}
placeholder={placeholder}
value={text}
disabled={disabled}
onChange={(e) => { onChange?.(e); set(e.target.value) }}
{...rest}
/>
{filled && !disabled && (
<button type="button" className={`${b}__clear`} aria-label="Clear search" onClick={() => { set(''); input.current?.focus() }}>
<span className={`${b}__clear-glyph`} aria-hidden="true" />
</button>
)}
<span className={`${b}__focus-ring`} aria-hidden="true" />
</div>
)
}
The source for everything on this page: contracts/search-field.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: search-field
name: SearchField
kind: component
status: review
summary: "Search above a list: a 40px field with the search icon, Input's colours and focus ring, and a clear button once there's something in it."
category: inputs
related: [ input, combobox, command ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "773:37"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=773-37
extractedAt: "2026-11-30"
extractedBy: hand
frozenAt: "2026-11-30"
props:
label: { type: string, required: true, notes: "What it searches, for screen readers: Search invoices. The field has no visible label; the icon and the placeholder say what it is." }
placeholder: { type: string, default: Search, notes: "What the empty field says." }
value: { type: string, notes: "What's typed. Controlled: pair it with `onValueChange`." }
filled: { type: boolean, default: false, notes: "There's something typed. SearchField sets it; it shows the clear button." }
states: [ Default, Hover, Focus, Disabled, ClearFocus ]
stateSelectors:
Focus: ":has(.rost-search-field__input:focus-visible)"
Disabled: ":has(.rost-search-field__input:disabled)"
ClearFocus: ":has(.rost-search-field__clear:focus-visible)"
elements:
root:
notes: "The box: 40px tall, 12px in at the sides, Input's 12px corners, with the edge drawn inside. A press anywhere puts the caret in the field."
styles:
display: { value: flex, assert: false }
align-items: { value: center }
position: { value: relative, assert: false }
gap: { token: spacing/gap/small, value: 8px }
height: { token: spacing/size/medium, value: 40px }
width: { value: 240px, notes: "The size of the Figma frame. In a page it's as wide as the list it narrows." }
padding-left: { token: spacing/gap/small-medium, value: 12px }
padding-right: { token: spacing/gap/small-medium, value: 12px }
border-radius: { token: spacing/radius/medium, value: 12px }
outline-style: { value: solid, assert: false }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside the box." }
cursor: { value: text, assert: false }
icon:
notes: "Rost's search icon, 20px, in Input's icon colour."
styles:
display: { value: block, assert: false }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
mask: { value: url(./icon-search.svg) center / contain no-repeat, untokenised: The icon file itself. }
input:
notes: "The real `<input type=\"search\">`, filling the rest of the box, its own look taken away. Paragraph type."
styles:
flex: { value: 1 1 0, assert: false }
min-width: { value: "0", assert: false }
height: { value: 100%, assert: false }
padding: { value: "0", assert: false }
border: { value: none, assert: false }
background: { value: transparent, assert: false }
outline: { value: none, assert: false }
appearance: { value: none, assert: false }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/paragraph/font-weight/regular, value: "400" }
font-size: { token: typography/paragraph/font-size, value: 14px }
line-height: { token: typography/paragraph/line-height, value: 20px }
letter-spacing: { token: typography/paragraph/letter-spacing, value: 0px }
input-placeholder:
pseudo: "::placeholder"
of: input
notes: "What the empty field says, in Input's label grey."
styles:
color: { token: search-field/placeholder, value: "#999999" }
clear:
optional: true
notes: "A 24px round button with Input's clear glyph, on the right when there's something typed. It empties the field and puts the focus back in it."
styles:
display: { value: flex, assert: false }
align-items: { value: center }
justify-content: { value: center }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/size/small, value: 24px }
height: { token: spacing/size/small, value: 24px }
padding: { value: "0", assert: false }
border: { value: none, assert: false }
border-radius: { token: spacing/radius/full, value: 10000px }
background: { value: none, assert: false }
cursor: { value: pointer, assert: false }
clear-glyph:
notes: "Input's clear glyph, 16px, in the value's colour."
styles:
display: { value: block, assert: false }
width: { token: spacing/size/2xsmall, value: 16px }
height: { token: spacing/size/2xsmall, value: 16px }
mask: { value: url(./icon-clear.svg) center / contain no-repeat, untokenised: The icon file itself. }
background: { token: search-field/value, value: "#c2c7c3" }
focus-ring:
notes: "Input's ring, 4px outside the box."
styles:
display: { value: none, assert: false }
position: { value: absolute, assert: false }
inset: { value: "calc(-1 * var(--spacing-gap-2xsmall))", untokenised: "Composed from a token: the ring sits spacing/gap/2xsmall outside the box." }
border-style: { value: solid, assert: false }
border-width: { token: spacing/outline/medium, value: 2px }
border-radius: { token: spacing/radius/large, value: 16px }
pointer-events: { value: none, assert: false }
variants:
- when: { filled: false }
elements:
clear:
display: { value: none, assert: false }
- when: { state: Default, filled: false }
figmaNode: "773:3"
elements:
root:
background: { token: search-field/background, value: "#060805" }
outline-color: { token: search-field/edge, value: "#747573" }
icon:
background: { token: search-field/icon, value: "#00d669" }
input:
color: { token: search-field/value, value: "#c2c7c3" }
- when: { state: Default, filled: true }
figmaNode: "773:9"
elements:
root:
background: { token: search-field/background, value: "#060805" }
outline-color: { token: search-field/edge, value: "#747573" }
icon:
background: { token: search-field/icon, value: "#00d669" }
input:
color: { token: search-field/value, value: "#c2c7c3" }
- when: { state: Hover, filled: false }
figmaNode: "773:18"
elements:
root:
background: { token: search-field/hover/background, value: "#171717" }
outline-color: { token: search-field/hover/edge, value: "#999999" }
icon:
background: { token: search-field/hover/icon, value: "#00b450" }
input:
color: { token: search-field/value, value: "#c2c7c3" }
- when: { state: Focus, filled: false }
figmaNode: "773:24"
elements:
root:
background: { token: search-field/background, value: "#060805" }
outline-color: { token: search-field/edge, value: "#747573" }
icon:
background: { token: search-field/icon, value: "#00d669" }
input:
color: { token: search-field/value, value: "#c2c7c3" }
focus-ring:
display: { value: block, assert: false }
border-color: { token: search-field/focus-ring, value: "#00d669" }
- when: { state: Disabled, filled: false }
figmaNode: "773:31"
elements:
root:
background: { token: search-field/disabled/background, value: "#171717" }
outline-color: { token: search-field/disabled/edge, value: "#3a3a3a" }
cursor: { value: default, assert: false }
icon:
background: { token: search-field/disabled/icon, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16", notes: "As Input's icon does when it's disabled." }
input:
color: { token: search-field/disabled/value, value: "#555555" }
input-placeholder:
color: { token: search-field/disabled/value, value: "#555555" }
- when: { state: Hover, filled: true }
elements:
root:
background: { token: search-field/hover/background, value: "#171717" }
outline-color: { token: search-field/hover/edge, value: "#999999" }
icon:
background: { token: search-field/hover/icon, value: "#00b450" }
input:
color: { token: search-field/value, value: "#c2c7c3" }
- when: { state: Focus, filled: true }
elements:
root:
background: { token: search-field/background, value: "#060805" }
outline-color: { token: search-field/edge, value: "#747573" }
icon:
background: { token: search-field/icon, value: "#00d669" }
input:
color: { token: search-field/value, value: "#c2c7c3" }
focus-ring:
display: { value: block, assert: false }
border-color: { token: search-field/focus-ring, value: "#00d669" }
- when: { state: Disabled, filled: true }
elements:
clear:
display: { value: none, assert: false }
root:
background: { token: search-field/disabled/background, value: "#171717" }
outline-color: { token: search-field/disabled/edge, value: "#3a3a3a" }
cursor: { value: default, assert: false }
icon:
background: { token: search-field/disabled/icon, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16", notes: "As Input's icon does when it's disabled." }
input:
color: { token: search-field/disabled/value, value: "#555555" }
- when: { state: ClearFocus }
elements:
clear:
outline: { value: "var(--spacing-outline-medium) solid var(--search-field-focus-ring)", untokenised: "Composed from tokens: a 2px ring in search-field/focus-ring." }
outline-offset: { value: "0", assert: false }
guidance:
status: proposed
use:
- title: Narrowing a list
text: "Above a list or a table: invoices by client, the docs by title. The list narrows as you type."
show: "state=Default, filled=False"
avoid:
- title: Picking one value
text: "When the answer is one item for a form, that's a **Combobox**."
- title: A whole-app search
text: "Jumping anywhere from the keyboard is **Command**."
behaviour: "It's a field: what to do with what's typed is the app's, usually narrowing the list under it as you type. The clear button shows once there's something typed, empties it and puts the focus back. Esc empties it too, the browser's way."
accessibility:
element: "A real `<input type=\"search\">` inside a `role=\"search\"` box, so it's found as a search landmark."
name: "`label`, as `aria-label` on the input. The clear button says Clear search."
keyboard: "Tab reaches the field, then the clear button when it shows. Esc empties the field."
focus: "`focus-ring` around the box, on `:focus-visible`."
colour: "Input's: the edge is 4.3:1 on the dark page, the placeholder 7:1."
content: "A placeholder that says what's searched, when Search alone isn't enough: Search invoices."
Install
npx github:Runceanu/rost add search-field It lands in src/rost/search-field/, with what it needs and its contract. Install has the rest.
When to use
Narrowing a list
Above a list or a table: invoices by client, the docs by title. The list narrows as you type.
When not to use
Picking one value
When the answer is one item for a form, that's a Combobox.
A whole-app search
Jumping anywhere from the keyboard is Command.
Behaviour
It's a field: what to do with what's typed is the app's, usually narrowing the list under it as you type. The clear button shows once there's something typed, empties it and puts the focus back. Esc empties it too, the browser's way.
Accessibility
- Element
A real
<input type="search">inside arole="search"box, so it's found as a search landmark. - Name
label, asaria-labelon the input. The clear button says Clear search. - Keyboard
Tab reaches the field, then the clear button when it shows. Esc empties the field.
- Focus
focus-ringaround the box, on:focus-visible. - Colour
Input's: the edge is 4.3:1 on the dark page, the placeholder 7:1.
Content
A placeholder that says what's searched, when Search alone isn't enough: Search invoices.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
label | string | | |
placeholder | string | | Search |
value | string | | |
filled | boolean | | false |
States: Default, Hover, Focus, Disabled, ClearFocus.
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
gap8pxspacing/gap/small -
height40pxspacing/size/medium -
width240pxno token yet -
padding-left12pxspacing/gap/small-medium -
padding-right12pxspacing/gap/small-medium -
border-radius12pxspacing/radius/medium -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside the box.
displayflex · align-itemscenter · positionrelative · outline-stylesolid · cursortext
icon
-
width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
maskurl(./icon-search.svg) center / contain no-repeaton purpose: The icon file itself.
displayblock · flex-shrink0
input
-
font-family'General Sans Variable'font-family/base -
font-weight400typography/paragraph/font-weight/regular -
font-size14pxtypography/paragraph/font-size -
line-height20pxtypography/paragraph/line-height -
letter-spacing0pxtypography/paragraph/letter-spacing
flex1 1 0 · min-width0 · height100% · padding0 · bordernone · backgroundtransparent · outlinenone · appearancenone
input-placeholder
-
color#999999search-field/placeholder
clear
-
width24pxspacing/size/small -
height24pxspacing/size/small -
border-radius10000pxspacing/radius/full
displayflex · align-itemscenter · justify-contentcenter · flex-shrink0 · padding0 · bordernone · backgroundnone · cursorpointer
clear-glyph
-
width16pxspacing/size/2xsmall -
height16pxspacing/size/2xsmall -
maskurl(./icon-clear.svg) center / contain no-repeaton purpose: The icon file itself. -
background#c2c7c3search-field/value
displayblock
focus-ring
-
border-width2pxspacing/outline/medium -
border-radius16pxspacing/radius/large
displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · border-stylesolid · pointer-eventsnone
Changes by variant
9 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.
Follows state
All but ClearFocus
| Property | Default | Hover | Focus | Disabled |
|---|---|---|---|---|
icon.backgroundsearch-field/… | icon #00d669 | hover/icon #00b450 | icon #00d669 | disabled/icon #b6ffda |
input.colorsearch-field/… | value #c2c7c3 | value #c2c7c3 | value #c2c7c3 | disabled/value #555555 |
root.backgroundsearch-field/… | background #060805 | hover/background #171717 | background #060805 | disabled/background #171717 |
root.outline-colorsearch-field/… | edge #747573 | hover/edge #999999 | edge #747573 | disabled/edge #3a3a3a |
Only in some variants
These don't change: they're just set in some variants and not others.
In 5 variants
-
clear.displaynonelayout
ClearFocus
-
clear.outlinevar(--spacing-outline-medium) solid var(--search-field-focus-ring)on purpose: Composed from tokens: a 2px ring in search-field/focus-ring. -
clear.outline-offset0Figma frame size
Focus
-
focus-ring.border-color#00d669search-field/focus-ring -
focus-ring.displayblocklayout
Disabled
-
icon.opacity0.16opacity/soft -
root.cursordefaultFigma frame size
Not filled · Disabled
-
input-placeholder.color#555555search-field/disabled/value