Slider

Choose a number, or a range with two thumbs, by dragging or with the arrow keys.

Status: beta. Category: Forms.

import { Slider } from '@glyphui/ui'

Exports: Slider, sliderStyles.

Notes

  • Use onValueCommit for expensive work such as network requests; it fires once when the thumb is released.
  • Range thumbs are named "Minimum" and "Maximum" by default; change them with thumbLabels.

Example: Single value

showValue displays the value above the thumb.

import { Field, Slider } from '@glyphui/ui'

export default function Example() {
  return (
    <Field label="Volume" className="max-w-sm">
      <Slider defaultValue={60} showValue={(v) => `${v}%`} marks={[0, 50, 100]} />
    </Field>
  )
}

Example: Range

Pass a [min, max] tuple; onValueChange returns a tuple.

import { Slider, Text } from '@glyphui/ui'
import { useState } from 'react'

export default function Example() {
  const [price, setPrice] = useState<readonly [number, number]>([200, 800])
  return (
    <div className="grid max-w-sm gap-3">
      <Slider<readonly [number, number]>
        value={price}
        onValueChange={setPrice}
        min={0}
        max={1000}
        step={50}
        minStepsBetweenThumbs={1}
        thumbLabels={['Minimum price', 'Maximum price']}
      />
      <Text size="small" tone="muted">
        ${price[0]} – ${price[1]}
      </Text>
    </div>
  )
}

Live page: https://glyphui.xyz/components/slider