useColorWheel

Provides the behavior and accessibility implementation for a color wheel component. Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.

Example
ColorWheel.tsx
ColorWheel.css
ColorThumb.css
import {ColorWheel} from './ColorWheel';

<ColorWheel defaultValue="hsl(30, 100%, 50%)" />

API

Shows a color wheel component with labels pointing to its parts, including the track, and thumb elements.TrackThumb
<ColorWheel>
  <ColorWheelTrack />
  <ColorThumb />
</ColorWheel>
useColorWheelState(props: ): useColorWheel( props: , state: , inputRef: <HTMLInputElementnull> ):

ColorWheelState

Properties

NameType
huenumber

The current value of the hue channel displayed by the color wheel.

isDraggingboolean

Whether the color wheel is currently being dragged.

pageStepnumber

The page step value of the hue channel, used when incrementing and decrementing.

isDisabledboolean

Whether the color wheel is disabled.

value

The current color value represented by the color wheel.

defaultValue

The default color value.

Methods

setValue(value: string): void
Sets the color value represented by the color wheel, and triggers onChange.
setHue(value: number): void
Sets the hue channel of the current color value and triggers onChange.
setHueFromPoint( x: number, y: number, radius: number ): void
Sets the hue channel of the current color value based on the given coordinates and radius of the color wheel, and triggers onChange.
getThumbPosition(radius: number): {
'x': number,
'y': number
}
Returns the coordinates of the thumb relative to the center point of the color wheel.
increment(stepSize?: number): void
Increments the hue by the given amount (defaults to 1).
decrement(stepSize?: number): void
Decrements the hue by the given amount (defaults to 1).
setDragging(value: boolean): void
Sets whether the color wheel is being dragged.
getDisplayColor():
Returns the color that should be displayed in the color wheel instead of value.

AriaColorWheelOptions

NameType
outerRadiusnumber

The outer radius of the color wheel.

innerRadiusnumber

The inner radius of the color wheel.

isDisabledboolean

Whether the ColorWheel is disabled.

valueT

The current value (controlled).

defaultValuestring

The default value (uncontrolled).

onChange(value: ) => void

Handler that is called when the value changes, as the user drags.

onChangeEnd(value: ) => void

Handler that is called when the user stops dragging.

ColorWheelAria

NameType
trackPropsDOMAttributes

Props for the track element.

thumbPropsDOMAttributes

Props for the thumb element.

inputPropsInputHTMLAttributes<HTMLInputElement>

Props for the visually hidden range input element.