Skip to content

AlphaSlider

AlphaSlider

A slider for a color's opacity, drawn over a checkerboard, horizontal (mirrored in right-to-left layouts) or vertical (bottom to top); transparency shows transparency instead. The arrow keys move by 1 %, 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 "Opacity" ("Transparency"). 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 AlphaSlider, with value/onValueChange for its color/onChange.

Examples

Default

export const Default: Story = {};

Transparency

export const Transparency: Story = {
  args: { transparency: true },
};

Vertical

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

Props

NameTypeRequiredDefaultDescription
transparencybooleanNofalse

Shows transparency (100 % is fully transparent) instead of opacity: the rail, the input's value, the value text and the arrow direction all follow it, while value.a stays the opacity (Fluent's transparency).

labelsAlphaSliderLabelsNo

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

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.

formstringNo

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

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.

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.

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).

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.

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

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

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.

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.

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

Parts

  • root
  • rail
  • thumb

Stable class names

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