The Unified Color Picker component allows for a fully accessible and configurable
color picker, allowing the user to pick from a set of predefined colors
(swatches), or to pick a custom color using a HSB selection interface.
It can be configured to show one or both of those color selection interfaces.
The Color Picker is a dynamic component with several 'live' areas. These
areas need to update when certain user interactions occur.
A quick note on terms
Several terms are used in this document, each with particular meaning. Please take note
of the following:
- Need/s This rule must be implemented for the component to appear or function as expected.
- Current color The current selected, submitted, and validated color.
- Working color The working, unsubmitted color, built with the custom-range tool.
When creating an implementation of this UI component, please take note to include
the following functionality:
Aside from the 'swatches-only' variant, all Color Picker variants have a summary
section with a clickable button. This button needs to toggle the visibility of the
This swatch needs an inline style of
background, set to the current color.
It needs to update whenever the current color is updated.
This input needs to display the hex value of the current color. It should update
whenever current color is updated. The user can enter a hex color manually. The
implementation should check for the validity of the submitted value before setting
the color to be the current color.
In the custom picker, the hue slider is a range input element that allows the user to
select a hue base for a working color. Its value ranges from 0 - 360, and represents the
hue in an expected hsv color format.
When the user updates the current color, the value on this slider needs to be adjusted
to the current color's hue.
The custom range represents a matrix of all saturation and brightness combinations of
the working color's hue. The x axis of the form represents saturation, and goes from
0% to 100%. On the y axis, brightness is represented, with 0% brightness at the bottom,
and 100% brightness at the top.
Keep in mind that when implementing color conversions, this custom range picker is utilizing
the HSB/HSV color model, and not the HSL model.
This element needs an inline style, with the
background property set to the
working color's hue, as defined by the hue range input element desctibed above. As this
element is meant to represent the current working color's hue's saturation and lightness
matrix, css's hsl() syntax is the most appropriate format here, with the hue being the
current working color's hue, the saturation set to 100% and the lightness set to 50%
(the 50% lightness is to adjust this HSL range for the HSB color model).
A gradient overlay will produce the effect of the saturation and brightness matrix
Any mouse clicks on the custom range need to set the position of the
.slds-color-picker__range-indicator to the clicked coordinates, and also need to
update the saturation and brightness values on the working color.
This is the targeting element inside the custom range, and represents the current
brightness and saturation values of the working color.
It needs declarations for
left positioning, so it will be properly
placed over the correct area of the
Conveniently, the values are uniformly represented. The
left declaration indicates
the saturation value, from 0% to 100%, and the
bottom declaration indicates
the brightness value, from 0% to 100%.
This swatch is a preview element of the working color value from the hue slider
and range indicator above. It needs an inline style for
background, set to the
completed working color value.
The Hex, R(ed), G(reen), and B(lue) text inputs included in this section are
representative of the current working color's converted Hex or RGB values, and
need to display those as their value.
Users can, however, directly input into these elements. A valid entry needs to
update the working color and update related elements. The implementation should
protect against invalid submissions.
Expected Keyboard Interactions
This element has the role of
listbox, and keyboard interactions when its <a>
children are focused needs to behave in a menu-like fashion. Keypresses need
to move the actively focused element in the appropriate direction (left/up will move
to the previous item, down/right will move to the next item).
Additionally, when focused on the first or last item, the appropriate key action
needs to move the focus to the last or first item, respectively. It is expected
to behave in a cyclical fashion.
The range indicator, when focused, needs to respond to arrow keypresses by moving
1% in the appropriate direction, unless prohibited by a boundary.
For an additional effect, if an arrow key is pressed in combination with shift,
the indicator can move 10% in the given direction, unless prohibited by a boundary.
Other expected keyboard interactions (such as input field updates) and their effects
on UI can be found in the Implementation Guidelines section above.
As this is a highly interactive component, there are some key accessibility
guidelines that must be followed.
This element needs a for attribute with the value of the
This element needs a
This element needs a
This element needs a
Since this element is focused and moved to indicate the working color it needs
proper aria tags to indicate its job and value. First, an
needs to be set to
aria-atomic needs to be set to
aria-describedby needs to reference the instructions text for the custom color
picker range, which in our example is the hidden
All Other Accessibility
This component makes use of other components, such as Popovers, Tabs, and Input.
All accessibility rules and guidelines for those components need to be followed
for proper accessibility support.