Rost

← All components

component

Select

One choice from a list that's too long to show. Input's filled field, with a chevron, and the browser's own list when it opens.

In code Contract: review Guidance: proposed Contract on GitHub Figma 738:29 As markdown

Try it

Every variant

Default · Not error
Disabled · Not error
Invoices in this currency need a bank account
Default · Error

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

Install

npx github:Runceanu/rost add select

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

When to use

  • One out of many

    A choice from a list of six or more, or a list that changes: a country, a client, a currency.

When not to use

Behaviour

It looks like Input once Input has a value: the label small at the top, the value under it, and a chevron on the right. The list that opens is the browser's own, so it works with the keyboard, on a phone and with a screen reader without any work of mine, but I can't style it. With error it takes Input's red, and the help line under it says what to fix. A disabled select has no error look: there's nothing to fix in a field you can't change.

Accessibility

  • Element

    A real <select>, named by its <label>.

  • Name

    label. Keep it short: it's the question the value answers.

  • Keyboard

    Tab reaches it. Space, Enter or the arrow keys open it and move through it, the browser's way.

  • Focus

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

  • Error

    error sets aria-invalid, and the help line is tied to the select with aria-describedby, so the reason is read out with it. Red is never the only sign: the words say what's wrong.

  • Colour

    The field's edge is 4.3:1 on the dark page, the same as Input's.

Content

Options in sentence case, in an order that makes sense: alphabetical, or the most likely first.

Props

PropTypeValuesDefault
label slot
children slot
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

positionabsolute · inset0 · appearancenone · backgroundtransparent · bordernone · outlinenone · cursorpointer

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

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