A ColorSwatch displays a preview of a selected color.
Accessibility
By default, ColorSwatch includes a localized color description for screen reader users (e.g. "dark vibrant blue"). Use the colorName prop to override this. Set an aria-label to provide additional context. In this example, a screen reader will announce "Fire truck red, Background color".
import {ColorSwatch} from './ColorSwatch';
<ColorSwatch
color="#f00"
aria-label="Background color"
colorName="Fire truck red" />
API
| Name | Type | |
|---|---|---|
color | string | Color | |
The color value to display in the swatch. | ||
colorName | string | |
A localized accessible name for the color. By default, a description is generated from the color value, but this can be overridden if you have a more specific color name (e.g. Pantone colors). | ||
style | StyleOrFunction | |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | |
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
id | string | |
The element's unique identifier. See MDN. | ||
aria-label | string | |
Defines a string value that labels the current element. | ||
aria-labelledby | string | |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
slot | string | null | |
A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit | ||
render | DOMRenderFunction | |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
Default className: react-aria-ColorSwatch
| Render Prop | |
|---|---|
color | |
| The color of the swatch. | |