ColorField

Used to let customers input any color, for example statuses of features or integrations.

View in Storybook

Anatomy

The hexamdecimal value can be altered to display any colour needed in a ColorField.

Anatomy
  1. Label (optional): A title for a ColorField to describe its purpose.
  2. Swatch: A visualisation of the selected colour swatch.
  3. helpMessage (optional): When a label is not required, longer helpful text can be added.
  4. Prefix: To signify the acceptable type of value.
  5. Value: Displays the hexadecimal value that has been entered.

 


States

 

Focused

Upon clicking a ColorField, the onFocus state is displayed by default and any placeholder text is removed.

Focused

 

Entered

When a value has been input, the text color darkens.

Entered

 

Error

Error validation messages appear underneath the ColorField when there has been an invalid input. Any error should be displayed as soon as the user has interacted with the ColorField and removed when interacted with again and the error has been fixed.

Error

 

Disabled

A disabled ColorField prevents user interaction. It doesn’t appear in the tab order, can’t receive focus, and may not read aloud by a screenreader.

Disabled

 

ReadOnly

A read-only ColorField prevents user modification but its contents can be selectable.

ReadOnly

 


Properties

ColorField offers further props for customisation when necessary within the product UI.

null

helpMessage

 

A single validation message may be displayed to provide helpful information for a user to complete their task. It is most commonly used to explain why a value is invalid so they can correct it and submit the form.

null

Hidden label

 

It may sometimes be necessary to hide labels, but label text must still be made available for screen readers. Placeholder text should be made visible in these instances for users to understand what text to input.

 


Usage

Users can add a custom hexadecimal value into the ColorField or pick from a set of pre-defined color swatches underneath the component, inside a DropdownMenu.

Custom value

 

Picker

When selecting, the ColorField displays a picker of pre-defined color swatches underneath the component, inside a DropdownMenu.

Picker

Picker

 


 

Best practice

  • Always show the color swatch and value, even when it is not editable when it can be edited.
  • Clearly label the purpose of a ColorField and what the colour will be used for.
  • Validate input as soon as it has been interacted with.

 

Do's and Don'ts

Do

Don't

✅ Use helper text for important information.

🚫 Add essential text as placeholder, use the helpMessage prop.

✅ Display the label as it provides further context and remains when the user is adding information. This can be hidden when necessary.

🚫 Remove the label as it incurs accessibility issues.

✅ Use to provide a value input.

🚫 Remove the value or color swatch.

✅ Keep the field to its shortest possible width.

 

 

Also see