Rost

← All components

component

NumberField

A number you nudge: minus, the value, plus, in a 48px box with Input's colours. For counts and quantities, not for prices.

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

Try it

Every variant

Default
Disabled

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

Install

npx github:Runceanu/rost add number-field

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

When to use

  • Small counts

    Seats on a plan, copies to print, nights in a stay: whole numbers people change by one or two.

When not to use

Behaviour

Minus and plus move it by step, and switch off at min and max. You can type into it too: when you leave the field, what you typed is read as a number and kept inside min and max, and anything that isn't a number puts the last good value back.

Accessibility

  • Element

    The input is role="spinbutton" with aria-valuenow, aria-valuemin and aria-valuemax, the ARIA pattern for a number you step through. Minus and plus are <button>s with tabindex="-1", since the keys below do what they do.

  • Name

    label, as aria-label on the input. The buttons say Decrease and Increase.

  • Keyboard

    Up and Down step by one step, Page Up and Page Down by ten, Home and End go to min and max when there are any.

  • Focus

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

  • Colour

    Input's: the edge is 4.3:1 on the dark page, the number 11:1.

Content

Whole numbers. Put the unit in the label (Nights), not in the field.

Props

PropTypeValuesDefault
label string
value number
min number
max number
step number 1

States: Default, Hover, Focus, Disabled, DecrementHover, IncrementHover, DecrementOff, IncrementOff.

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 4px spacing/gap/2xsmall
  • height 48px spacing/size/medium-large
  • width 160px no token yet
  • padding 4px spacing/gap/2xsmall
  • 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.

displayinline-flex · align-itemscenter · positionrelative · outline-stylesolid

decrement

  • width 40px spacing/size/medium
  • height 40px spacing/size/medium
  • border-radius 8px spacing/radius/small

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

decrement-glyph

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

displayblock

input

  • font-family 'General Sans Variable' font-family/base
  • font-weight 500 typography/paragraph/font-weight/medium
  • 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 · text-aligncenter · font-variant-numerictabular-nums

increment

  • width 40px spacing/size/medium
  • height 40px spacing/size/medium
  • border-radius 8px spacing/radius/small

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

increment-glyph

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

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

8 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

In 4 variants

PropertyDefaultHoverFocusDisabled
input.colornumber-field/… value #c2c7c3 value #c2c7c3 value #c2c7c3 disabled/value #555555
root.backgroundnumber-field/… background #060805 hover/background #171717 background #060805 disabled/background #171717
root.outline-colornumber-field/… edge #747573 hover/edge #999999 edge #747573 disabled/edge #3a3a3a

In 5 variants

PropertyDefaultHoverFocusDisabledDecrementOffIncrementOff
decrement-glyph.backgroundnumber-field/… step #00d669 step #00d669 step #00d669 disabled/step #b6ffda disabled/step #b6ffda·
increment-glyph.backgroundnumber-field/… step #00d669 step #00d669 step #00d669 disabled/step #b6ffda· disabled/step #b6ffda

Only in some variants

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

In 2 variants

  • decrement-glyph.opacity 0.16 opacity/soft
  • decrement.cursor default Figma frame size
  • increment-glyph.opacity 0.16 opacity/soft
  • increment.cursor default Figma frame size

DecrementHover

  • decrement.background #006f27 number-field/step-hover/background

Focus

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

IncrementHover

  • increment.background #006f27 number-field/step-hover/background