Color Input

A field for a hex color. The swatch on the left shows the color and opens a Color Picker in a popover. You can also type the code.

General

Name the field with a label passed as children. Without a visible label, use aria-label.

With swatches

swatches shows colors to pick with one click inside the popover.

Brand colors

Two labeled fields side by side, with a preview that follows them as they change.

Variants

Use filled, light, ghost or subtle with a type, and rounded, to change the surface of the field.

Disabled

Shows the color and blocks the field and the swatch.

APIs

ColorInput.Props

AttributeDescriptionTypeAccepted valuesDefault
valuethe color, to control the componentstring'#rrggbb', '#rgb'-
initialValuethe color on the first renderstring'#rrggbb', '#rgb'#000000
onChangecalled with the color as #rrggbb in lowercase(hex: string) => void--
swatchescolors to pick with one click in the popoverstring[]--
placeholdertext shown when the field is emptystring-#000000
pickerLabelname of the swatch button and of the dialogstring-Choose color
disableddisable the componentboolean-false
typecolor of the fieldNormalTypes'default', 'primary', 'secondary', 'success', 'warning', 'error', 'info'default
roundedround the cornersboolean-false
filledfilled variantboolean-false
lightlight variantboolean-false
ghostoutline variantboolean-false
subtlesubtle variantboolean-false
...native props, passed to the inputInputHTMLAttributes'aria-label', 'name', ...-

Typing

The color changes as soon as the text holds six digits, with or without the #. A short code like #abc is read when the field loses the focus, and becomes #aabbcc. Any other text is dropped on blur, and the field goes back to the current color. The field always holds a color, so it cannot be left empty.

Ref

The ref points at the input.

Accessibility

The field is named by its label, or by aria-label. The swatch is a button with aria-haspopup="dialog" and aria-expanded, named by pickerLabel. The picker opens in a dialog with the focus on its square. Escape closes it and puts the focus back on the swatch. The code is also a text in the field, so the color is not conveyed by the swatch alone. See Color Picker for the keys.

Edit this page on GitHub