Skip to Content
Referencefusion-uiComponentsControlsSlider

Slider

The Slider component allows users to select a value from a range.


() => {
  const [value, setValue] = React.useState(0.5);
  return <Slider value={value} onChange={setValue} />;
}

Features

The Slider component is a versatile component that can be used in a variety of ways.

Tooltip

You can display a tooltip that shows the current value.


() => {
  const [value, setValue] = React.useState(0.5);
  return (
    <Slider
      value={value}
      onChange={setValue}
      tooltip={(progress) => <Tooltip label={Math.round(progress * 100)} />}
    />
  );
}
Note

For more information, see the Tooltip component.

Persistent Tooltip

The tooltip can be made to be always visible.


() => {
  const [value, setValue] = React.useState(0.5);
  return (
    <Slider
      value={value}
      onChange={setValue}
      persistentTooltip
      tooltip={(progress) => <Tooltip label={Math.round(progress * 100)} />}
    />
  );
}

Disabled State

You can disable the slider to prevent user interaction.


() => {
  const [value, setValue] = React.useState(0.5);
  return <Slider value={value} onChange={setValue} disabled />;
}

Drag End

You can listen for when the user stops dragging the handle. This can be useful if you don’t want to update the value on every drag. For example, if you’re using a slider to control the seek position of a video, you don’t want to update the value on every drag, but only when the user stops dragging.


() => {
  const [value, setValue] = React.useState(0.5);
  const [finalValue, setFinalValue] = React.useState(value);
  return (
    <Column gap={400} align="center">
      <Slider value={value} onChange={setValue} onDragEnd={setFinalValue} />
      <Text font={5}>{finalValue.toFixed(2)}</Text>
    </Column>
  );
}

Limitations

Range

Warning

At the moment, the Slider does not support min and max props. The value must always be between 0 and 1. If you’re after a different range, you will need to map the value to your desired range manually.


() => {
  const [value, setValue] = React.useState(0);
  return (
    <Column gap={400} align="center">
      <Slider
        value={(value + 1) / 2}
        onChange={(value) => setValue(value * 2 - 1)}
      />
      <Text font={5}>{value.toFixed(2)}</Text>
    </Column>
  );
}

Step

Warning

The Slider component does not support a step prop just yet. The value is always continuous. You can however, use the onChange prop to round the value to a specific step. The example below shows how to round the value to the nearest 10.


() => {
  const [value, setValue] = React.useState(50);
  return (
    <Column gap={400} align="center">
    <Slider
      value={value / 100}
        onChange={(value) => setValue(Math.round(value * 10) * 10)}
      />
      <Text font={5}>{value}</Text>
    </Column>
  );
}

Control

Warning

The Slider component can only be used as a controlled component. You must provide a value and onChange prop.

Anatomy

1.SliderThe slider itself is a `Box` component.
2.TrackThe track that the handle slides on is a `LinearProgress` component.
3.HandleThe handle that the user can drag.

Reference

Props

The Slider component inherits all of the props from the Box component and adds the following props.

NameTypeDefaultDescription
valuenumber-The current value of the slider.
onChange(value: number) => void-Callback fired when the value changes.
onDragEnd(value: number) => void-Callback fired when the user stops dragging the handle.
persistentTooltipbooleanfalseWhether the tooltip is always visible.
disabledbooleanfalseWhether the slider is disabled.
tooltip(progress: number) => ReactNode-A function that returns a tooltip to display.
initialbooleanfalseWhether to animate the initial progress.
transitionTransition-The transition to use for the progress animation.

Tokens

KeyDefault Value
slider.row.base.borderRadiusnone
slider.row.variants.disabled.true.opacityvar(--_1i4ikbk2i)
slider.track.base.heightcalc(var(--gpqiqca) / 4)
slider.track.variants.active.true.backgroundColorvar(--_1i4ikbk0)
slider.track.variants.active.true.:hover.backgroundColorcolor-mix(in srgb, var(--_1i4ikbk0) 95%, var(--_1i4ikbkv) 5%)
slider.track.variants.active.true.:focus-visible.backgroundColorcolor-mix(in srgb, var(--_1i4ikbk0) 95%, var(--_1i4ikbkv) 5%)
slider.track.variants.active.true.:active.backgroundColorcolor-mix(in srgb, var(--_1i4ikbk0) 95%, var(--_1i4ikbkv) 5%)
slider.track.variants.active.true.:disabled.backgroundColorvar(--_1i4ikbk0)
slider.track.variants.active.false.backgroundColorvar(--_1i4ikbk12)
slider.track.variants.active.false.:hover.backgroundColorvar(--_1i4ikbk12)
slider.track.variants.active.false.:focus-visible.backgroundColorvar(--_1i4ikbk12)
slider.track.variants.active.false.:active.backgroundColorvar(--_1i4ikbk12)
slider.track.variants.active.false.:disabled.backgroundColorvar(--_1i4ikbk12)
slider.handle.base.backgroundColorvar(--_1i4ikbk0)
slider.handle.base.borderRadiusvar(--gpqiqdz)
slider.handle.base.heightvar(--gpqiqca)
slider.handle.base.widthvar(--gpqiqca)
slider.handle.base.:hover.backgroundColorcolor-mix(in srgb, var(--_1i4ikbk0) 95%, var(--_1i4ikbkv) 5%)
slider.handle.base.:focus-visible.backgroundColorcolor-mix(in srgb, var(--_1i4ikbk0) 95%, var(--_1i4ikbkv) 5%)
slider.handle.base.:focus-visible.outlineWidthvar(--_1i4ikbk2e)
slider.handle.base.:focus-visible.outlineStylevar(--_1i4ikbk2f)
slider.handle.base.:focus-visible.outlineColorvar(--_1i4ikbk2g)
slider.handle.base.:focus-visible.outlineOffsetvar(--_1i4ikbk2h)
slider.handle.base.:active.backgroundColorcolor-mix(in srgb, var(--_1i4ikbk0) 95%, var(--_1i4ikbkv) 5%)
slider.handle.base.:disabled.backgroundColorvar(--_1i4ikbk0)
Last updated on