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 hue slider or alpha slider, sets the value to min.-
EndIf within hue slider or alpha slider, sets the value to max.-
PageUpIf within hue slider or alpha slider, increases the value based on min and max.-
PageDownIf within hue slider or alpha slider, decreases the value based on min and max.-

ARIA Roles and Attributes

Component and ElementRoles and AttributesUsage
div.ui-color-picker__fieldrole="combobox"Indicates that this is a combobox.
aria-controlsIf the dialog is open, sets the id of the related div.ui-color-picker__content when closed, sets undefined.
aria-describedbyIf this 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.
div.ui-color-picker__eye-dropperrole="button"Indicates that this is a button.
aria-disabledSets to "true" if disabled or readOnly is set.
aria-labelSets to "Pick a color".
div.ui-color-picker__contentrole="dialog"Indicates that this is a dialog.
div.ui-color-selector__saturation-slider > inputaria-hiddenExcludes the element from the accessibility tree.
aria-describedbyIf this is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
div.ui-color-selector__saturation-slider > divrole="slider"Indicates that this is a slider.
aria-labelSets to "Saturation and brightness thumb".
aria-describedbyIf this is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
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%".
div.ui-color-selector__hue-slider > inputaria-hiddenExcludes the element from the accessibility tree.
aria-describedbyIf this is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
div.ui-color-selector__hue-slider > divrole="slider"Indicates that this is a slider.
aria-labelSets to "Slider thumb".
aria-describedbyIf this is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
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".
div.ui-color-selector__alpha-slider > inputaria-hiddenExcludes the element from the accessibility tree.
aria-describedbyIf this is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
div.ui-color-selector__alpha-slider > divrole="slider"Indicates that this is a slider.
aria-labelSets to "Slider thumb".
aria-describedbyIf this is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
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%".
span.ui-color-selector__color-swatch-group-labelidUsed to associate with div.ui-color-selector__color-swatch-group.
div.ui-color-selector__color-swatch-grouprole="listbox"Indicates that this is a listbox.
aria-labelledbySets the id of the associated span.ui-color-selector__color-swatch-group-label.
div.ui-color-selector__color-swatch-itemrole="option"Indicates that this is an option.
aria-labelSets the current value.
aria-roledescriptionSets to "color swatch".
aria-selectedSets to "true" if value is the same as the current value.

Similar Components

ColorSelector

ColorSelector is a component used by the user to select a color.

AlphaSlider

AlphaSlider is a component used to allow the user to select color transparency.

DatePicker

DatePicker is a component used for users to select a date.

HueSlider

HueSlider is a component used to allow the user to select a color hue.

SaturationSlider

SaturationSlider is a component used to allow the user to select a color saturation.

Select

Select is a component used for allowing a user to choose values from a list of options.

Uses Components & Hooks