Build faster with Premium Chakra UI Components 💎

Learn more
Skip to Content
DocsPlaygroundGuidesBlog
Sponsor

Color Picker

Used to select colors from a color area or a set of defined swatches

SourceStorybookRecipeArk

Setup

If you don't already have the snippet, run the following command to add the color-picker snippet

npx @chakra-ui/cli snippet add color-picker

The snippet includes a closed component composition for the ColorPicker component.

Usage

import {
  ColorPickerArea,
  ColorPickerContent,
  ColorPickerControl,
  ColorPickerEyeDropper,
  ColorPickerInput,
  ColorPickerLabel,
  ColorPickerRoot,
  ColorPickerSliders,
  ColorPickerTrigger,
} from "@/components/ui/color-picker"
<ColorPickerRoot>
  <ColorPickerLabel />
  <ColorPickerControl>
    <ColorPickerInput />
    <ColorPickerTrigger />
  </ColorPickerControl>
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerEyeDropper />
    <ColorPickerSliders />
  </ColorPickerContent>
</ColorPickerRoot>

Examples

Sizes

Use the size prop to change the size of the color picker.

Variants

Use the variant prop to change the visual style of the color picker. Values can be either outline or subtle.

Input Only

Combine the ColorPickerValueSwatch and the ColorPickerEyeDropper on the InputGroup to render a color picker that contains only an input.

Swatch Only

Use the ColorPickerSwatchGroup and ColorPickerSwatchTrigger to render only the color swatches.

Trigger Only

Compose the color picker to initially show only a trigger using the ColorPickerValueSwatch and ColorPickerValueText.

Trigger Inside Input

Compose the color picker to trigger in input using the InputGroup and ColorPickerInput.

Controlled

Use the value and onValueChange props to control the state of the color picker.

Change End

Use the onValueChangeEnd to listen to when the user finishes selecting a color, rather than while they are scrubbing or dragging through the color area.

onChangeEnd: #EB5E41

Channel Slider

Combine the ColorPickerChannelSliders and the format prop to add the different color channels to the color picker.

Hook Form

Here's an example of how to integrate the color picker with react-hook-form.

Inline

Use the ColorPickerInlineContent and pass open to the ColorPickerRoot to display an inline version of the color picker.

Disabled

Pass the disabled prop to disable the color picker.

Channel Input

Use the ChannelFormatSelect and ColorPickerChannelInputs to create a color picker that allows users to select their preferred channel.

Fit Content

Here's an example of how to create a rounded trigger that fits the content.

ReadOnly

Use the readOnly prop to make the color picker component read-only.

Save Swatch

Here's an example of how to save a selected color as a swatch.

Swatches

Here's an example of how to combine the color picker with pre-defined swatches.

Swatch and Input

Here's how to compose a swatch with an input.

Swatch and Trigger

Here's how to compose a swatch with a trigger.

Props

Root

PropDefaultType
closeOnSelect false
boolean

Whether to close the color picker when a swatch is selected

format '\'rgba\''
ColorFormat

The color format to use

lazyMount false
boolean

Whether to enable lazy mounting

unmountOnExit false
boolean

Whether to unmount on exit.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
defaultOpen
boolean

The initial open state of the color picker when it is first rendered. Use when you do not need to control its open state.

defaultValue
string

The initial value of the color picker when it is first rendered. Use when you do not need to control the state of the color picker.

disabled
boolean

Whether the color picker is disabled

id
string

The unique identifier of the machine.

ids
Partial<{ root: string; control: string; trigger: string; label: string; input: string; hiddenInput: string; content: string; area: string; areaGradient: string; positioner: string; formatSelect: string; areaThumb: string; channelInput(id: string): string; channelSliderTrack(id: ColorChannel): string; channelSliderT...

The ids of the elements in the color picker. Useful for composition.

immediate
boolean

Whether to synchronize the present change immediately or defer it to the next frame

initialFocusEl
() => HTMLElement | null

The initial focus element when the color picker is opened.

name
string

The name for the form input

onExitComplete
() => void

Function called when the animation ends in the closed state

onFocusOutside
(event: FocusOutsideEvent) => void

Function called when the focus is moved outside the component

onFormatChange
(details: FormatChangeDetails) => void

Function called when the color format changes

onInteractOutside
(event: InteractOutsideEvent) => void

Function called when an interaction happens outside the component

onOpenChange
(details: OpenChangeDetails) => void

Handler that is called when the user opens or closes the color picker.

onPointerDownOutside
(event: PointerDownOutsideEvent) => void

Function called when the pointer is pressed down outside the component

onValueChange
(details: ValueChangeDetails) => void

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

onValueChangeEnd
(details: ValueChangeDetails) => void

Handler that is called when the user stops dragging.

open
boolean

Whether the color picker is open

positioning
PositioningOptions

The positioning options for the color picker

present
boolean

Whether the node is present (controlled by the user)

readOnly
boolean

Whether the color picker is read-only

required
boolean

Whether the color picker is required

value
string

The current value of the color picker.

Previous

Collapsible

Next

Color Swatch