Skip to content

Slider

Slider

A native range input with Fluent styling: a rail drawn in the accessible stroke color (3:1 against the page), filled in the primary color up to a primary thumb; in forced-colors mode the rail, fill and thumb are drawn in system colors. Inside a Field it picks up the label, hint, validation message, required and invalid state automatically.

The fill follows the value through the --wave-slider-progress variable on the input (also in the server HTML), including the browser's snapping to step and a form reset.

size (small, medium) sets the thumb and rail dimensions; the input carries data-size. orientation="vertical" runs the rail up (see its docs); the input carries data-orientation. Slider does not read a surrounding Field's size or a WaveProvider's input defaults.

Examples

Default

export const Default: Story = {};

Min Max

export const MinMax: Story = {
  args: {
    label: 'Temperature',
    min: 0,
    max: 100,
    defaultValue: 25,
  },
};

With Step

export const WithStep: Story = {
  args: {
    label: 'Quantity',
    min: 0,
    max: 50,
    step: 5,
    defaultValue: 10,
  },
};

Disabled

export const Disabled: Story = {
  args: {
    label: 'Brightness',
    disabled: true,
  },
};

Sizes

export const Sizes: Story = {
  render: (args) => (
    <div className="grid gap-4">
      <Slider {...args} size="small" defaultValue={30} aria-label="Small volume" />
      <Slider {...args} size="medium" defaultValue={60} aria-label="Medium volume" />
    </div>
  ),
};

Right To Left

export const RightToLeft: Story = {
  args: {
    defaultValue: 30,
  },
  render: (args) => (
    <div dir="rtl" className="w-64">
      <Slider {...args} />
    </div>
  ),
};

Vertical

export const Vertical: Story = {
  render: (args) => (
    <div className="flex items-end gap-8">
      <Slider {...args} orientation="vertical" size="small" aria-label="Small volume" />
      <Slider {...args} orientation="vertical" aria-label="Medium volume" />
      <Slider {...args} orientation="vertical" className="h-48" aria-label="Tall volume" />
      <Slider {...args} orientation="vertical" disabled aria-label="Disabled volume" />
    </div>
  ),
};

Props

NameTypeRequiredDefaultDescription
valuenumberNo

Controlled slider value.

defaultValuenumberNo

Initial value for uncontrolled usage.

onChangeReact.ChangeEventHandler<HTMLInputElement>No

Native change event handler (event.target.value is a string).

onValueChange(value: number) => voidNo

Called with the new value as a number on every change, next to the native onChange.

minnumberNo

Minimum allowed value.

maxnumberNo

Maximum allowed value.

stepnumberNo

Step increment between values.

labelstringNo

Accessible label for the slider (sets aria-label; an explicit aria-label wins). Inside a Field, leave it out so the Field's label names the slider.

size'small' | 'medium'No'medium'

Size of the thumb and rail: the 0.7 20px thumb on a 4px rail, or a small 16px thumb on a 2px rail in a 24px-tall input. Unlike the text controls and pickers, Slider does not read a surrounding Field's size or a WaveProvider's input defaults: this prop is the only source of its size.

orientation'horizontal' | 'vertical'No'horizontal'

Direction of the rail (Fluent UI's vertical flag, named as the other components name it): horizontal, or vertical, which runs the rail up with the minimum at the bottom, sets aria-orientation="vertical" and gives the slider a default height of 8rem (set another with className="h-48"; a vertical slider is as wide as its thumb). The up and right arrow keys raise the value in both. A vertical slider does not mirror in a right-to-left page. It needs a browser that lays a range input out in a vertical writing mode (recent Chrome, Edge, Firefox and Safari); an older one draws it horizontally.

refReact.Ref<HTMLInputElement>No

Ref to the <input type="range"> element.

Any other prop is passed to the element it renders (HTMLInputElement).

Stable class names

PartClass
rootwave-slider