ColorPicker

ColorPicker is a component used by the user to select a color or enter an arbitrary color value.

Usage

import { ColorPicker } from "@yamada-ui/react"
<ColorPicker />

Change Variant

Change Size

Change Color Scheme

Set Default Value

To set a default value, set defaultValue to a value.

Set Alpha Value

To set an alpha value, set defaultValue to a value containing an alpha value or set format to "hexa" or "hsla" etc.

Change Format

To change the format, set format to a value. The default is to determine the format from the string of value or defaultValue.

Limit Input Value

To limit the input value, set pattern to a regular expression.

Format Input Value

To format the input value, set formatInput to a function.

Show Color Swatches

To show color swatches, set colorSwatches to an array.

Change Color Swatch Columns

To change the number of columns in the color swatch group, set colorSwatchGroupColumns to a number.

Change Offset

To change the offset, set gutter or offset to a value.

Change Animation Scheme

To change the animation scheme, set animationScheme to "block-start" or "inline-end" etc. The default is "scale".

Change Placement

To change the placement, set placement to "end" or "start-center" etc. The default is "end-start".

Blocking Scroll

To block scrolling, set blockScrollOnMount to true.

Close Dropdown On Scroll

To close the dropdown on scroll, set closeOnScroll to true.

Handle Opening Dropdown On Change

To handle the event of opening the dropdown on change, set a function to openOnChange.

Handle Closing Dropdown On Change

To handle the event of closing the dropdown on change, set a function to closeOnChange.

Disable Open Dropdown On Focus

To disable opening the dropdown on focus, set openOnFocus to false.

Disable Open Dropdown On Click

To disable opening the dropdown on click, set openOnClick to false.

Disable Close On Outside Click

To disable closing the dropdown on outside click, set closeOnBlur to false.

Disable Close On Esc

To disable closing the dropdown on ESC key, set closeOnEsc to false.

Disable Allow Input

To disable allowing input, set allowInput to false.

Change Shape

Disable

To disable, set disabled to true.

Make Read Only

To make read only, set readOnly to true.

Make Invalid

To make invalid, set invalid to true.

Change Border Color

To change the border color, set focusBorderColor or errorBorderColor to a value.

Control

Props

Accessibility

ColorPicker follows the WAI-ARIA - Combobox Pattern for accessibility.

If you do not use Field.Root, set aria-label or aria-labelledby on ColorPicker.

<ColorPicker placeholder="#4387f4" aria-label="Pick color" />
<VStack gap="sm">
  <Text as="h3" id="label">
    Pick Color
  </Text>

  <ColorPicker placeholder="#4387f4" aria-labelledby="label" />
</VStack>

Keyboard Navigation

KeyDescriptionState
TabOpens the dialog when focus moves to the color picker.openOnFocus={true}
EscapeCloses the dialog.closeOnEsc={true}
ArrowRight, ArrowUpIf within a slider, increases the value based on step.-
ArrowLeft, ArrowDownIf within a slider, decreases the value based on step.-
HomeIf within HueSlider or AlphaSlider, sets the value to min.-
EndIf within HueSlider or AlphaSlider, sets the value to max.-
PageUpIf within HueSlider or AlphaSlider, increases the value based on min and max.-
PageDownIf within HueSlider or AlphaSlider, decreases the value based on min and max.-

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
ColorPickerFieldrole="combobox"Indicates that this is a combobox.
aria-controlsIf the dialog is open, sets the id of the related ColorPickerContent; when closed, sets undefined.
aria-describedbyIf ColorPicker is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
aria-disabledSets to "true" if disabled or readOnly is set.
aria-expandedSets to "true" when the dialog is open, "false" when closed.
aria-haspopup="dialog"Indicates that a dialog exists.
aria-invalidSets to "true" if invalid is set.
aria-readonlySets to "true" if readOnly is set.
aria-requiredSets to "true" if required is set.
ColorPickerEyeDropperrole="button"Indicates that this is a button.
aria-disabledSets to "true" if disabled or readOnly is set.
aria-labelSets to "Pick a color".
ColorPickerContentrole="dialog"Indicates that this is a dialog.
ColorPickerColorSwatchrole="img"Indicates that this is an image.
aria-labelSets the current value.
aria-roledescriptionSets to "color swatch".
SaturationSlider.Thumbrole="slider"Indicates that this is a slider.
aria-labelSets to "Saturation and brightness thumb".
aria-roledescriptionSets to "2D slider".
aria-valueminSets the value of min. The default is 0.
aria-valuemaxSets the value of max. The default is 100.
aria-valuenowSets the current value.
aria-valuetextSets the current value like "Saturation 18%, Brightness 18%".
HueSlider.Thumbrole="slider"Indicates that this is a slider.
aria-labelSets to "Slider thumb".
aria-orientationSets to "horizontal" or "vertical" based on orientation. The default is "horizontal".
aria-valueminSets the value of min. The default is 0.
aria-valuemaxSets the value of max. The default is 360.
aria-valuenowSets the current value.
aria-valuetextSets the current value like "18°, Red".
AlphaSlider.Thumbrole="slider"Indicates that this is a slider.
aria-labelSets to "Slider thumb".
aria-orientationSets to "horizontal" or "vertical" based on orientation. The default is "horizontal".
aria-valueminSets the value of min. The default is 0.
aria-valuemaxSets the value of max. The default is 1.
aria-valuenowSets the current value.
aria-valuetextSets the current value like "18%".