ColorWheel

Circular hue selector

Usage

ColorWheel is a circular hue selector. Its value is a hue in degrees, a number between 0 and 360:

Size
Thickness
Thumb size
Saturation
Lightness
import { ColorWheel } from '@mantine/core';

function Demo() {
  return <ColorWheel aria-label="Color wheel" thumbSize={20} />;
}

Controlled

Convert the value to a color with the hsl(hue, 100%, 50%) syntax or with any color conversion function:

Hue: 210°

import { useState } from 'react';
import { ColorSwatch, ColorWheel, Group, Stack, Text } from '@mantine/core';

function Demo() {
  const [hue, setHue] = useState(210);

  return (
    <Stack align="center">
      <Group>
        <ColorSwatch color={`hsl(${hue}, 100%, 50%)`} />
        <Text size="sm">Hue: {hue}°</Text>
      </Group>
      <ColorWheel aria-label="Color wheel" value={hue} onChange={setHue} />
    </Stack>
  );
}

The value starts at the top of the ring (0° is red) and increases clockwise: 90° is on the right, 180° at the bottom, 270° on the left.

Ring colors

Use saturation and lightness props (numbers between 0 and 100) to change the ring colors. These props change only the appearance, the value is always the hue in degrees:

saturation=100 lightness=50

saturation=60 lightness=70

import { ColorWheel, Group, Stack, Text } from '@mantine/core';

function Demo() {
  return (
    <Group justify="center">
      <Stack align="center" gap="xs">
        <ColorWheel aria-label="Vivid" saturation={100} lightness={50} defaultValue={210} />
        <Text size="sm">saturation=100 lightness=50</Text>
      </Stack>

      <Stack align="center" gap="xs">
        <ColorWheel aria-label="Pastel" saturation={60} lightness={70} defaultValue={210} />
        <Text size="sm">saturation=60 lightness=70</Text>
      </Stack>
    </Group>
  );
}

Size and thickness

Use size prop to change the outer diameter of the wheel and thickness prop to change the ring width. The thumb size is calculated from thickness, use thumbSize prop to override it.

import { ColorWheel } from '@mantine/core';

function Demo() {
  return <ColorWheel size={220} thickness={40} thumbSize={20} />;
}

onChangeEnd

The onChangeEnd callback fires when the user stops dragging the wheel or changes its value with the keyboard. Use it as a debounced callback to prevent frequent updates:

Current value: 0

End value: 0

import { useState } from 'react';
import { ColorWheel, Text } from '@mantine/core';

function Demo() {
  const [value, setValue] = useState(0);
  const [endValue, setEndValue] = useState(0);

  return (
    <>
      <ColorWheel
        aria-label="Color wheel"
        value={value}
        onChange={setValue}
        onChangeEnd={setEndValue}
      />
      <Text mt="md">Current value: {value}</Text>
      <Text>End value: {endValue}</Text>
    </>
  );
}

Without thumb indicator

Set withThumbIndicator={false} to hide the thumb. The component stays interactive and keyboard accessible:

import { ColorWheel } from '@mantine/core';

function Demo() {
  return <ColorWheel withThumbIndicator={false} />;
}

Disabled

The disabled prop disables the component and prevents user interaction:

import { ColorWheel } from '@mantine/core';

function Demo() {
  return <ColorWheel aria-label="Color wheel" defaultValue={210} disabled />;
}

ColorWheel with uncontrolled forms

Set name prop to include the hue value in the FormData object on form submission. Use defaultValue prop to set the initial value and hiddenInputProps to pass additional props to the hidden input.

import { ColorWheel } from '@mantine/core';

function Demo() {
  return (
    <form
      onSubmit={(event) => {
        event.preventDefault();
        const formData = new FormData(event.currentTarget);
        console.log('Hue value:', formData.get('hue'));
      }}
    >
      <ColorWheel name="hue" defaultValue={120} />
      <button type="submit">Submit</button>
    </form>
  );
}

Accessibility

To make the component accessible for screen readers, set the aria-label prop:

import { ColorWheel } from '@mantine/core';

function Demo() {
  return <ColorWheel aria-label="Hue" />;
}

Keyboard interactions when the thumb is focused. Arrow keys wrap around: decreasing from 0 moves to the last step before 360.

KeyDescription
ArrowDownDecreases value by step
ArrowLeftDecreases value by step
ArrowUpIncreases value by step
ArrowRightIncreases value by step
HomeSets value to 0
EndSets value to the last step before 360 (359 with the default step)

Based on use-radial-move

ColorWheel is based on the use-radial-move hook, the same hook that powers the AngleSlider component. Use this hook to build a custom radial selector.

115°
import { useState } from 'react';
import { Box } from '@mantine/core';
import { useRadialMove } from '@mantine/hooks';
import classes from './Demo.module.css';

function Demo() {
  const [value, setValue] = useState(115);
  const { ref } = useRadialMove(setValue);

  return (
    <Box className={classes.root} ref={ref} style={{ '--angle': `${value}deg` }}>
      <div className={classes.value}>{value}°</div>
      <div className={classes.thumb} />
    </Box>
  );
}