ColorInput
Usage
Controlled
Formats
Component supports hex, rgb, rgba, hsl and hsla color formats. Slider to change opacity is displayed only for rgba and hsla formats:
Disable free input
To disable free input set disallowInput
prop:
With swatches
You can add any amount of predefined color swatches:
By default there will be 10 swatches per row, you can change this with swatchesPerRow
prop,
like in ColorPicker component:
If you need to restrict color picking to certain colors – disable color picker and disallow free input:
Remove or replace preview
By default color preview will be rendered on the left side of the input,
you can remove it (withPreview={false}
prop) or replace with any React node (icon
prop):
Input props
Component supports all props from Input and InputWrapper components:
Right section
Like most other inputs ColorInput supports right section, for example, you can add random color button there:
Disabled state
Validation state and error
Get input ref
You can get input ref with ref
prop:
Accessibility
Color picker focus
Color picker is not focusable, users without mouse access can select color only by entering it into input manually. If you want to make component accessible do not disable free input.
aria-label
Provide aria-label
in case you use component without label for screen reader support: