Provides the behavior and accessibility implementation for a color field component. Color fields allow users to enter and adjust a hex color value.
import {ColorField} from './ColorField';
<ColorField label="Primary Color" defaultValue="#ff0000" />
API
<ColorField>
<Label />
<Input />
<Text slot="description" />
<FieldError />
</ColorField>
useColorFieldState (props: ColorFieldProps ): ColorFieldStateuseColorField(
props: AriaColorFieldProps,
state: ColorFieldState,
ref: RefObject <HTMLInputElement | null >
): ColorFieldAriaColorFieldState
Properties
| Name | Type | |
|---|---|---|
colorValue | Color | null | |
The currently parsed color value, or null if the field is empty.
Updated based on the | ||
defaultColorValue | Color | null | |
The default value of the color field. | ||
realtimeValidation | ValidationResult | |
Realtime validation results, updated as the user edits the value. | ||
displayValidation | ValidationResult | |
Currently displayed validation results, updated when the user commits their changes. | ||
inputValue | string | |
The current text value of the input. Updated as the user types,
and formatted according to | ||
Methods
setColorValue | ||
| Sets the color value of the field. | ||
setInputValue | ||
| Sets the current text value of the input. | ||
commit | ||
| Updates the input value based on the currently parsed color value. Typically this is called when the field is blurred. | ||
increment | ||
Increments the current input value to the next step boundary, and fires onChange. | ||
decrement | ||
Decrements the current input value to the next step boundary, and fires onChange. | ||
incrementToMax | ||
Sets the current value to the maximum color value, and fires onChange. | ||
decrementToMin | ||
Sets the current value to the minimum color value, and fires onChange. | ||
validate | ||
| Validates a user input string. Values can be partially entered, and may be valid even if they cannot currently be parsed to a color. Can be used to implement validation as a user types. | ||
updateValidation | ||
Updates the current validation result. Not displayed to the user until commitValidation is
called. | ||
resetValidation | ||
| Resets the displayed validation state to valid when the user resets the form. | ||
commitValidation | ||
| Commits the realtime validation so it is displayed to the user. | ||
AriaColorFieldProps
| Name | Type | |
|---|---|---|
isWheelDisabled | boolean | |
Enables or disables changing the value with scroll. | ||
isDisabled | boolean | |
Whether the input is disabled. | ||
isReadOnly | boolean | |
Whether the input can be selected but not changed by the user. | ||
placeholder | string | |
Temporary text that occupies the text input when it is empty. | ||
value | T | |
The current value (controlled). | ||
defaultValue | T | |
The default value (uncontrolled). | ||
onChange | | |
Handler that is called when the value changes. | ||
ColorFieldAria
| Name | Type | |
|---|---|---|
labelProps | LabelHTMLAttributes | |
Props for the label element. | ||
inputProps | InputHTMLAttributes | |
Props for the input element. | ||
descriptionProps | DOMAttributes | |
Props for the text field's description element, if any. | ||
errorMessageProps | DOMAttributes | |
Props for the text field's error message element, if any. | ||
validationDetails | ValidityState | |
The native validation details for the input. | ||