Rost

← All components

component

Combobox

One choice from a long list, found by typing. Select's field you can type in, and the matching options in a list under it.

In code Contract: review Guidance: proposed Contract on GitHub Figma 756:58 As markdown

Try it

Every variant

Client One
Client Two
Client Three
Client Four
Client Five
Client Six
Client Seven
Default · Not error
Client One
Client Two
Client Three
Client Four
Client Five
Client Six
Client Seven
Disabled · Not error
This client has no VAT number yet
Client One
Client Two
Client Three
Client Four
Client Five
Client Six
Client Seven
Default · Error

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

Install

npx github:Runceanu/rost add combobox

It lands in src/rost/combobox/, with what it needs and its contract. Install has the rest.

When to use

  • Finding one in many

    A client out of a hundred, a country, a currency: a list long enough that typing a few letters beats scrolling.

When not to use

Behaviour

It looks like Select and uses Select's colours. Typing opens the list and keeps the options whose name contains what was typed, ignoring case; nothing matching says so. Up and Down move the highlight, Enter picks it, Esc closes the list. Leaving the field puts the picked option's name back, so a half-typed word never looks like an answer.

Accessibility

  • Element

    <input role="combobox"> with aria-expanded, aria-controls and aria-activedescendant, the ARIA pattern for a list that filters. The list is role="listbox" of role="option"s; the picked one has aria-selected.

  • Name

    label.

  • Keyboard

    The focus stays in the input the whole time; the highlight moves in the list and screen readers follow it through aria-activedescendant.

  • Focus

    focus-ring around the field, on :focus-visible.

  • Error

    error sets aria-invalid and ties the help line to the input.

  • Colour

    Select's: the edge is 4.3:1 on the dark page. The empty-list words are 7:1.

Content

Option names people would type: the client's name, not an id.

Props

PropTypeValuesDefault
label slot
options node
value string
placeholder string
empty string No match
supportive slot
error boolean false

States: Default, Hover, Focus, Disabled.

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

  • height 56px spacing/size/large
  • width 208px no token yet

displayblock · positionrelative

outline

  • border-style solid no token yet
  • border-width 1px spacing/outline/small
  • border-radius 12px spacing/radius/medium

positionabsolute · inset0 · pointer-eventsnone

label

  • top 12px spacing/gap/small-medium
  • left 12px spacing/gap/small-medium
  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/label/font-weight/regular
  • font-size 10px typography/placeholder/font-size
  • line-height 12px typography/placeholder/line-height
  • letter-spacing 0px typography/placeholder/letter-spacing

positionabsolute · pointer-eventsnone

field

  • padding-top 24px spacing/gap/large
  • padding-bottom 12px spacing/gap/small-medium
  • padding-left 12px spacing/gap/small-medium
  • padding-right 40px spacing/size/medium
  • 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

box-sizingborder-box · width100% · cursortext · positionabsolute · inset0 · appearancenone · backgroundtransparent · bordernone · outlinenone

chevron

  • top 20px spacing/gap/medium-large
  • right 12px spacing/gap/small-medium
  • width 20px spacing/size/xsmall
  • height 20px spacing/size/xsmall
  • mask url(./icon-chevron.svg) center / contain no-repeat on purpose: The icon file itself.

positionabsolute · pointer-eventsnone

supportive

  • left 12px spacing/gap/small-medium
  • top calc(var(--spacing-size-large) + var(--spacing-gap-2xsmall)) on purpose: Composed from tokens: the field's height plus spacing/gap/2xsmall.
  • font-family 'General Sans Variable' font-family/base
  • font-weight 500 typography/label/font-weight/medium
  • font-size 10px typography/placeholder/font-size
  • line-height 12px typography/placeholder/line-height
  • letter-spacing 0px typography/placeholder/letter-spacing

positionabsolute · white-spacenowrap

focus-ring

  • border-style solid no token yet
  • border-width 2px spacing/outline/medium
  • border-radius 16px spacing/radius/large

displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone

listbox

  • margin 0px spacing/gap/none
  • margin-block-start 8px spacing/gap/small
  • max-height 240px no token yet
  • padding 4px spacing/gap/2xsmall
  • border-radius 12px spacing/radius/medium
  • background #171717 combobox/listbox/background
  • 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 plate.
  • outline-color #3a3a3a combobox/listbox/edge
  • box-shadow 0px 16px 24px 0px rgba(0, 0, 0, 0.16) shadow/floating

insetauto · position-areablock-end span-inline-end · position-try-fallbacksflip-block · min-widthanchor-size(width) · overflow-yauto · bordernone · outline-stylesolid · colorinherit

empty

  • height 40px spacing/size/medium
  • padding-left 12px spacing/gap/small-medium
  • 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
  • color #999999 combobox/empty

displayflex · align-itemscenter

Changes by variant

7 variants. Each table is what one thing changes with: a column per error, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows error

Focus

PropertyNot errorError
focus-ring.border-colorselect/… focus/focus-ring #00d669 negative/focus/focus-ring #00d669

Follows state and error

Not error

PropertyDefaultHoverFocusDisabled
chevron.backgroundselect/… default/chevron #00d669 hover/chevron #00b450 focus/chevron #00d669 disabled/chevron #b6ffda
field.colorselect/… default/value #c2c7c3 hover/value #d3d9d5 focus/value #c2c7c3 disabled/value #555555
label.colorselect/… default/label #999999 hover/label #d3d9d5 focus/label #999999 disabled/label #555555
outline.backgroundselect/… default/background #060805 hover/background #171717 focus/background #060805 disabled/background #171717
outline.border-colorselect/… default/outline #747573 hover/outline #999999 focus/outline #747573 disabled/outline #3a3a3a
supportive.colorselect/… default/supportive #999999 hover/supportive #d3d9d5 focus/supportive #999999 disabled/supportive #555555

Error

PropertyDefaultHoverFocusDisabled
chevron.backgroundselect/negative/… default/chevron #e93120 hover/chevron #e93120 focus/chevron #e93120·
field.colorselect/negative/… default/value #999999 hover/value #999999 focus/value #c2c7c3·
label.colorselect/negative/… default/label #e93120 hover/label #f2705f focus/label #e93120·
outline.backgroundselect/negative/… default/background #060805 hover/background #171717 focus/background #060805·
outline.border-colorselect/negative/… default/outline #f2705f hover/outline #e93120 focus/outline #f2705f·
supportive.colorselect/negative/… default/supportive #e93120 hover/supportive #e93120 focus/supportive #e93120·

Only in some variants

These don't change: they're just set in some variants and not others.

Disabled

  • chevron.opacity 0.16 opacity/soft

Focus

  • focus-ring.display block layout

Part of Combobox

ComboboxOption

One option in a Combobox's list: a 40px row with its name. Green when it's highlighted, a green tick when it's the one picked.

In code Contract: review Guidance: proposed Contract on GitHub Figma 756:72 As markdown
Client One
Not selected · Not active
Client One
Not selected · Active
Client One
Selected · Not active
Client One
Selected · Active

Install

npx github:Runceanu/rost add combobox-option

It lands in src/rost/combobox-option/, with what it needs and its contract. Install has the rest.

When to use

  • The picked one, and the one you're on

    Medium weight and a tick for the picked option; the green row for the one the arrow keys are on. They can be the same row.

When not to use

  • On its own

    An option only makes sense in a Combobox's list, which sets active and selected.

Behaviour

Pressing it picks it and closes the list. Pointing at it highlights it, as the arrow keys do.

Accessibility

  • Element

    role="option" with an id, so the input can point at it with aria-activedescendant. The picked one has aria-selected="true". The tick is drawing.

  • Colour

    The names are 17:1 on the list's grey, 7:1 on the green. The tick is 10:1.

Props

PropTypeValuesDefault
selected boolean false
active boolean false
children slot

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
  • padding-left 12px spacing/gap/small-medium
  • padding-right 12px spacing/gap/small-medium
  • border-radius 8px spacing/radius/small
  • 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

displayflex · align-itemscenter · justify-contentspace-between · inline-size100% · cursorpointer · white-spacenowrap

check

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

displayblock · flex-shrink0

Changes by variant

4 variants. Each table is what one thing changes with: a column per active, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows active

Selected

PropertyNot activeActive
check.backgroundcombobox-option/… check #00d669 active/check #ededed
PropertyNot activeActive
root.colorcombobox-option/… default/label #ededed active/label #ededed

Only in some variants

These don't change: they're just set in some variants and not others.

Active

  • root.background #006f27 combobox-option/active/background

Selected

  • root.font-weight 500 typography/paragraph/font-weight/medium