Skip to content

ColorArea

ColorArea

A 2-D color field: saturation from left to right (mirrored in right-to-left layouts) and brightness from bottom to top, at the value's hue. ArrowLeft and ArrowRight move saturation by 1 %, ArrowUp and ArrowDown brightness; Shift with an arrow moves by 10, Page Up and Page Down move brightness by 10, and Home and End set saturation to 0 and 100. A press or drag (mouse, touch or pen) moves the thumb to the pointer. It is one Tab stop holding two sliders for assistive technology, "Saturation" and "Brightness", whose value texts start with their own channel and name the color; focus follows the axis a key moves, and unless the primary pointer is coarse (touch), only the slider with the Tab stop is exposed. Inside a ColorPicker, leave value and defaultValue out and it binds to the picker. Fluent's ColorArea, with value/onValueChange for its color/onChange.

Examples

Default

export const Default: Story = {};

Controlled

#0f6cbd

export const Controlled: Story = {
  render: function ControlledStory(args) {
    const [color, setColor] = useState<HsvColor>({ h: 208, s: 0.92, v: 0.74 });
    return (
      <div className="flex w-64 flex-col gap-3">
        <ColorArea
          {...args}
          value={color}
          onValueChange={(next) => {
            setColor(next);
            args.onValueChange?.(next);
          }}
        />
        <ColorSlider value={color} onValueChange={setColor} />
        <p className="text-wave-body-1 text-wave-foreground">{hsvToHex(color)}</p>
      </div>
    );
  },
};

Square

export const Square: Story = {
  args: { shape: 'square' },
};

Disabled

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

Props

NameTypeRequiredDefaultDescription
valueHsvColorNo

The color (Fluent's color). Inside a ColorPicker, leave value and defaultValue out to bind the area 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, a pointer move or assistive technology) that changes it (Fluent's onChange). A bound area calls it too.

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

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

labelsColorAreaLabelsNo

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

disabledbooleanNofalse

Unavailable: both inputs are natively disabled, pointer presses are ignored and the area is dimmed. A bound area 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 area 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 group supports neither, so neither is set on it.

controlRefReact.Ref<HTMLInputElement>No

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

refReact.Ref<HTMLDivElement>No

Ref to the root role="group" element.

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

Props for the elements the area draws inside its root, by part, merged into each part's own (Fluent UI's thumb slot prop; Fluent draws its field on the root): your classes after the part's (yours win a conflict), your styles over its styles, your handlers and attributes added, your ref beside its ref. Every attribute the area sets on a part is locked. A part takes no children. Both parts are drawn only: the two range inputs are the sliders, reached through the area's own props and controlRef. The area handles the pointer and the keys on its root, so an event on a part reaches your handler first: preventDefault() in your onPointerDown cancels that press (the thumb stays, no drag starts), while the area's own onPointerDown, a prop of its root, still runs.

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

Parts

  • field
  • thumb

Stable class names

PartClass
rootwave-color-area
fieldwave-color-area__field
thumbwave-color-area__thumb