Skip to content

ColorSlider

ColorSlider

A slider for one channel of an HSV color: hue (the default), saturation or brightness (channel="value"), horizontal (mirrored in right-to-left layouts) or vertical (bottom to top). The arrow keys move by 1 (hue in degrees, the others in percent), Shift with an arrow and Page Up or Page Down by 10, Home and End to the ends. It is named by aria-label, else the surrounding Field's label, else "Hue", "Saturation" or "Brightness"; a hue slider's value text names the color ("210°, blue"). Inside a ColorPicker, leave value and defaultValue out and it binds to the picker. ref reaches the range input, as the naming, validation and focus props do; className, style and data-* stay on the root (slotProps.root.ref reaches it). Fluent's ColorSlider, with value/onValueChange for its color/onChange and orientation for its vertical.

Examples

Default

export const Default: Story = {};

Saturation

export const Saturation: Story = {
  args: { channel: 'saturation', defaultValue: { h: 208, s: 0.6, v: 0.8 } },
};

Brightness

export const Brightness: Story = {
  args: { channel: 'value' },
};

Vertical

export const Vertical: Story = {
  args: { orientation: 'vertical' },
};

Right To Left

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

Props

NameTypeRequiredDefaultDescription
channel'hue' | 'saturation' | 'value'No'hue'

The channel the slider edits.

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

'vertical' draws the rail from bottom to top (Fluent's vertical).

valueHsvColorNo

The color (Fluent's color). Inside a ColorPicker, leave value and defaultValue out to bind the slider to the picker.

defaultValueHsvColorNothe brand blue, `{ h: 208, s: 0.92, v: 0.74 }` (`#0f6cbd`)

Initial color for uncontrolled usage (also what a form reset restores).

onValueChange(value: HsvColor) => voidNo

Called with the new color on every step (a key, the pointer or assistive technology) that changes it (Fluent's onChange). A bound slider calls it too.

shape'square' | 'rounded'No'rounded'

'square' removes the corner radius of the rail (the thumb stays round). Bound to a ColorPicker, the picker's shape unless you pass one.

labelsColorSliderLabelsNo

Texts of the slider; bound to a ColorPicker, the picker's labels fill the keys you leave out.

disabledbooleanNofalse

Unavailable: the input is natively disabled and the slider dimmed. A bound slider is also disabled while the picker's value is not a hex color.

namestringNo

Form field name: the color is submitted as hex (hsvToHex). Ignored while bound to a ColorPicker.

formstringNo

Id of the form the slider belongs to, when it is rendered outside that form.

requiredbooleanNo

Marks the hidden form input required (a color is always set, so it never blocks). A consumer aria-required does the same: a slider supports neither, so neither is set on it.

refReact.Ref<HTMLInputElement>No

Ref to the <input type="range">, the slider (Fluent UI's ref, on its primary element). The root <div> is slotProps.root.ref.

slotProps{ root?: SlotPart<'div'>; rail?: SlotPart<'div'>; thumb?: SlotPart<'span'> }No

Props for the elements the slider draws, by part, merged into each part's own (Fluent UI's root, rail and thumb slot props): your classes after the part's (yours win a conflict), your styles over its styles, your handlers and attributes added, your ref attached. Every attribute the slider sets on a part is locked. A part takes no children. The rail and the thumb are drawn only: the slider itself is the invisible range input over them, which takes the pointer and the keys and is reached through the slider's own props and ref, so a part receives no press of its own.

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

Parts

  • root
  • rail
  • thumb

Stable class names

PartClass
rootwave-color-slider
railwave-color-slider__rail
thumbwave-color-slider__thumb