Usage
ColorInput
component supports Input and Input.Wrapper components features and all input
element props. ColorInput
documentation does not include all features supported by the component – see Input documentation to learn about all available features.
Input description
Controlled
Formats
Component supports hex, hexa, rgb, rgba, hsl and hsla color formats. Slider to change opacity is displayed only for hexa, rgba and hsla formats:
Preserve invalid input
By default, ColorInput
will revert the value on blur to the last known valid value.
To change this behavior and keep invalid value, set fixOnBlur={false}
:
onChangeEnd
onChangeEnd
is called when user stops dragging slider or changes input value.
It is useful when you need to update color only when user finished interaction with the component:
Change end value: #FFFFFF
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 7 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:
Close dropdown on color swatch click
To close the dropdown when one of the color swatches is clicked, set closeOnColorSwatchClick
prop:
Hide dropdown
To hide dropdown, set withPicker={false}
:
Eye dropper
By default, if EyeDropper API
is available, eye dropper icon will be displayed at the right section of the input.
To disable it, set withEyeDropper={false}
:
Change eye dropper icon
You can replace eye dropper icon with any React node using eyeDropperIcon
prop:
Left and right sections
ColorInput
supports leftSection
and rightSection
props. These sections are rendered with absolute position inside the input wrapper. You can use them to display icons, input controls or any other elements.
You can use the following props to control sections styles and content:
rightSection
/leftSection
– React node to render on the corresponding side of inputrightSectionWidth
/leftSectionWidth
– controls width of the right section and padding on the corresponding side of the input. By default, it is controlled by componentsize
prop.rightSectionPointerEvents
/leftSectionPointerEvents
– controlspointer-events
property of the section. If you want to render a non-interactive element, set it tonone
to pass clicks through to the input.
Note that by default, ColorPicker
has color preview in the left section and eye dropper button
in the right section. You can replace these elements with any React node using leftSection
and rightSection
props:
Error state
Invalid name
Disabled state
Read only
Styles API
ColorInput
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow Styles API documentation to learn more.
Description
Error
Component Styles API
Hover over selectors to highlight corresponding elements
Get element ref
Accessibility
If ColorInput
is used without label
prop, it will not be announced properly by screen reader:
Set aria-label
to make the input accessible. In this case label will not be visible, but screen reader will announce it:
If label
prop is set, input will be accessible it is not required to set aria-label
: