Rost

← All components

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.

In code Contract: review Guidance: proposed Contract on GitHub Figma 773:37 As markdown

Try it

Every variant

Default · Not filled
Default · Filled
Disabled · Not filled

Hover, press or tab to one to see the other 2 states.

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

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.

Props

PropTypeValuesDefault
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

  • gap 8px spacing/gap/small
  • height 40px spacing/size/medium
  • width 240px no token yet
  • padding-left 12px spacing/gap/small-medium
  • padding-right 12px spacing/gap/small-medium
  • border-radius 12px spacing/radius/medium
  • outline-width 1px spacing/outline/small
  • outline-offset calc(-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

  • width 20px spacing/size/xsmall
  • height 20px spacing/size/xsmall
  • mask url(./icon-search.svg) center / contain no-repeat on purpose: The icon file itself.

displayblock · flex-shrink0

input

  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/paragraph/font-weight/regular
  • font-size 14px typography/paragraph/font-size
  • line-height 20px typography/paragraph/line-height
  • letter-spacing 0px typography/paragraph/letter-spacing

flex1 1 0 · min-width0 · height100% · padding0 · bordernone · backgroundtransparent · outlinenone · appearancenone

input-placeholder

  • color #999999 search-field/placeholder

clear

  • width 24px spacing/size/small
  • height 24px spacing/size/small
  • border-radius 10000px spacing/radius/full

displayflex · align-itemscenter · justify-contentcenter · flex-shrink0 · padding0 · bordernone · backgroundnone · cursorpointer

clear-glyph

  • width 16px spacing/size/2xsmall
  • height 16px spacing/size/2xsmall
  • mask url(./icon-clear.svg) center / contain no-repeat on purpose: The icon file itself.
  • background #c2c7c3 search-field/value

displayblock

focus-ring

  • border-width 2px spacing/outline/medium
  • border-radius 16px spacing/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

PropertyDefaultHoverFocusDisabled
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.display none layout

ClearFocus

  • clear.outline var(--spacing-outline-medium) solid var(--search-field-focus-ring) on purpose: Composed from tokens: a 2px ring in search-field/focus-ring.
  • clear.outline-offset 0 Figma frame size

Focus

  • focus-ring.border-color #00d669 search-field/focus-ring
  • focus-ring.display block layout

Disabled

  • icon.opacity 0.16 opacity/soft
  • root.cursor default Figma frame size

Not filled · Disabled

  • input-placeholder.color #555555 search-field/disabled/value