Rost

← All components

component

Slider

A number picked by dragging, when about right is right: a 4px track, a green fill and a 20px thumb. The arrow keys move it a step at a time.

In code Contract: review Guidance: proposed Contract on GitHub Figma 748:25 As markdown

Try it

Every variant

Default
Disabled

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

Install

npx github:Runceanu/rost add slider

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

When to use

  • Roughly how much

    A share to set aside, a zoom level, how many months to show: where nudging until it looks right beats typing.

When not to use

Behaviour

Press anywhere along it and the thumb jumps there; drag to move it. The arrow keys move one step, Page Up and Page Down ten, Home and End to the ends. It calls onValueChange with the new number; show that number next to it.

Accessibility

  • Element

    The thumb is role="slider" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext when it's given. The track and fill are drawing.

  • Name

    label, as aria-label on the thumb, or point aria-labelledby at a visible label.

  • Colour

    The thumb is 17:1 on the dark page and the fill 10:1. The track is 1.8:1, a quiet edge: the fill and thumb carry the value, not the track.

Content

Write the value beside it, in its units. The label says what it sets: Share set aside for tax.

Props

PropTypeValuesDefault
value number
min number 0
max number 100
step number 1
label string
valueText string
disabled boolean false

States: Default, 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 24px spacing/size/small

displayblock · positionrelative · touch-actionnone · cursorpointer

track

  • top calc(50% - var(--spacing-gap-2xsmall) / 2) on purpose: Composed from a token: the middle of the root, less half the track.
  • height 4px spacing/gap/2xsmall
  • border-radius 10000px spacing/radius/full
  • background #3a3a3a slider/track

positionabsolute · left0 · right0

fill

  • top calc(50% - var(--spacing-gap-2xsmall) / 2) on purpose: Composed from a token: on the track.
  • height 4px spacing/gap/2xsmall
  • border-radius 10000px spacing/radius/full
  • background #00d669 slider/fill

positionabsolute · left0

thumb

  • top 2px spacing/gap/3xsmall
  • width 20px spacing/size/xsmall
  • height 20px spacing/size/xsmall
  • border-radius 10000px spacing/radius/full
  • background #ededed slider/thumb

positionabsolute · outlinenone

focus-ring

  • border-width 2px spacing/outline/medium
  • border-radius 10000px spacing/radius/full

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

Only in some variants

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

Focus

  • focus-ring.border-color #999999 slider/focus-ring
  • focus-ring.display block layout

Disabled

  • root.cursor default Figma frame size
  • root.opacity 0.24 opacity/gentle