ColorInput
Usage
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:
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):
Eye dropper
Set withEyeDropper
prop to display eye dropper icon in the right section.
This feature depends on EyeDropper API,
the eye dropper will not be rendered if the API is not supported.
Input props
Right section
Disabled state
Validation state and error
Get input ref
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:
ColorInput component props
Name | Type | Description |
---|---|---|
closeOnColorSwatchClick | boolean | Determines whether the dropdown should be closed when color swatch is clicked, false by default |
defaultValue | string | Uncontrolled component default value |
description | ReactNode | Input description, displayed after label |
descriptionProps | Record<string, any> | Props spread to description element |
disabled | boolean | Disabled input state |
disallowInput | boolean | Disallow free input |
dropdownZIndex | number | Dropdown element z-index |
error | ReactNode | Displays error message after input |
errorProps | Record<string, any> | Props spread to error element |
eyeDropperIcon | ReactNode | Replaces default eye dropper icon |
eyeDropperLabel | string | aria-label for eye dropper button |
fixOnBlur | boolean | call onChange with last valid value onBlur |
format | "hex" | "hexa" | "rgba" | "rgb" | "hsl" | "hsla" | Color format |
icon | ReactNode | Adds icon on the left side of input |
iconWidth | Width<string | number> | Width of icon section |
inputContainer | (children: ReactNode) => ReactNode | Input container component, defaults to React.Fragment |
inputWrapperOrder | ("input" | "label" | "error" | "description")[] | Controls order of the Input.Wrapper elements |
label | ReactNode | Input label, displayed before input |
labelProps | Record<string, any> | Props spread to label element |
onChange | (color: string) => void | Called when color changes |
onChangeEnd | (color: string) => void | Called when user stops dragging thumb or changes value with arrows |
portalProps | Omit<PortalProps, "children" | "withinPortal"> | Props to pass down to the portal when withinPortal is true |
radius | number | "xs" | "sm" | "md" | "lg" | "xl" | Key of theme.radius or any valid CSS value to set border-radius, theme.defaultRadius by default |
required | boolean | Adds required attribute to the input and red asterisk on the right side of label |
rightSection | ReactNode | Right section of input, similar to icon but on the right |
rightSectionProps | Record<string, any> | Props spread to rightSection div element |
rightSectionWidth | Width<string | number> | Width of right section, is used to calculate input padding-right |
shadow | MantineShadow | Dropdown box-shadow, key of theme.shadows |
size | "xs" | "sm" | "md" | "lg" | "xl" | Input size |
swatches | string[] | Predefined colors |
swatchesPerRow | number | Number of swatches displayed in one row |
transitionProps | Partial<Omit<TransitionProps, "mounted">> | Props added to Transition component that used to animate dropdown presence, use to configure duration and animation type, { duration: 0, transition: 'fade' } by default |
value | string | Controlled component value |
variant | Variants<"unstyled" | "default" | "filled"> | Defines input appearance, defaults to default in light color scheme and filled in dark |
withAsterisk | boolean | Determines whether required asterisk should be rendered, overrides required prop, does not add required attribute to the input |
withEyeDropper | boolean | Determines whether eye dropper button should be displayed in the right section, true by default |
withPicker | boolean | Set to false to display swatches only |
withPreview | boolean | Display swatch with color preview on the left side of input |
withinPortal | boolean | Whether to render the dropdown in a Portal |
wrapperProps | Record<string, any> | Properties spread to root element |
ColorInput component Styles API
Name | Static selector | Description |
---|---|---|
wrapper | .mantine-ColorInput-wrapper | Root element |
icon | .mantine-ColorInput-icon | Input icon wrapper on the left side of the input, controlled by icon prop |
input | .mantine-ColorInput-input | Main input element |
rightSection | .mantine-ColorInput-rightSection | Input right section, controlled by rightSection prop |
root | .mantine-ColorInput-root | Root element |
label | .mantine-ColorInput-label | Label element styles, defined by label prop |
error | .mantine-ColorInput-error | Error element styles, defined by error prop |
description | .mantine-ColorInput-description | Description element styles, defined by description prop |
required | .mantine-ColorInput-required | Required asterisk element styles, defined by required prop |
body | .mantine-ColorInput-body | Includes hue and alpha sliders and color preview |
preview | .mantine-ColorInput-preview | Color preview |
sliders | .mantine-ColorInput-sliders | Hue and alpha sliders wrapper |
slider | .mantine-ColorInput-slider | Alpha and hue sliders |
sliderOverlay | .mantine-ColorInput-sliderOverlay | Hue and alpha sliders overlays |
thumb | .mantine-ColorInput-thumb | Hue, alpha and saturation sliders thumbs |
saturation | .mantine-ColorInput-saturation | Saturation slider |
swatch | .mantine-ColorInput-swatch | ColorSwatch component in swatches list |
swatches | .mantine-ColorInput-swatches | Wrapper around all swatches |
dropdown | .mantine-ColorInput-dropdown | Dropdown root element |
arrow | .mantine-ColorInput-arrow | Dropdown arrow |