Skip to content

Commit 1bbc82d

Browse files
authored
docs(color-slider): enhance README with detailed sections (#5728)
* docs(color-slider): enhance README with detailed sections * docs(color-slider): add keyboard shortcuts for hue adjustments in README * docs(color-slider): enhance README with accessible labels for color slider
1 parent b839f70 commit 1bbc82d

File tree

1 file changed

+114
-15
lines changed

1 file changed

+114
-15
lines changed

packages/color-slider/README.md

Lines changed: 114 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Description
1+
## Overview
22

33
An `<sp-color-slider>` lets users visually change an individual channel of a color. The background of the `<sp-color-slider>` is a visual representation of the range of values a user can select from. This can represent color properties such as hues, color channel values (such as RGB or CMYK levels), or opacity. Currently, the slider only supports leveraging the `hue` property.
44

@@ -8,23 +8,65 @@ An `<sp-color-slider>` lets users visually change an individual channel of a col
88
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/color-slider?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/color-slider)
99
[![Try it on Stackblitz](https://img.shields.io/badge/Try%20it%20on-Stackblitz-blue?style=for-the-badge)](https://stackblitz.com/edit/vitejs-vite-enye2vau)
1010

11-
```
11+
```bash
1212
yarn add @spectrum-web-components/color-slider
1313
```
1414

1515
Import the side effectful registration of `<sp-color-slider>` via:
1616

17-
```
17+
```javascript
1818
import '@spectrum-web-components/color-slider/sp-color-slider.js';
1919
```
2020

2121
When looking to leverage the `ColorSlider` base class as a type and/or for extension purposes, do so via:
2222

23-
```
23+
```javascript
2424
import { ColorSlider } from '@spectrum-web-components/color-slider';
2525
```
2626

27-
## Color Formatting
27+
### Anatomy
28+
29+
The color slider consists of several key parts:
30+
31+
- A gradient track showing the range of color values
32+
- A draggable handle that indicates the current color position
33+
- An accessible label for screen readers
34+
35+
```html
36+
<sp-color-slider></sp-color-slider>
37+
```
38+
39+
### Options
40+
41+
#### Orientation
42+
43+
By default, the color slider is displayed horizontally. You can change the orientation to vertical using the `vertical` attribute:
44+
45+
```html
46+
<sp-color-slider vertical></sp-color-slider>
47+
```
48+
49+
### States
50+
51+
#### Standard
52+
53+
The standard color slider allows users to select hue values from 0 to 360 degrees:
54+
55+
```html
56+
<sp-color-slider></sp-color-slider>
57+
```
58+
59+
#### Disabled
60+
61+
A color slider in a disabled state shows that an input exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that the slider may become available later.
62+
63+
```html
64+
<sp-color-slider disabled></sp-color-slider>
65+
```
66+
67+
### Behaviors
68+
69+
#### Color Formatting
2870

2971
When using the color elements, use `el.color` to access the `color` property, which should manage itself in the colour format supplied. If you supply a color in `rgb()` format, `el.color` should return the color in `rgb()` format, as well.
3072

@@ -36,23 +78,80 @@ The current color formats supported are as follows:
3678
- RGB, RGBA
3779
- Strings (eg "red", "blue")
3880

81+
For a complete list of supported color formats, see the [ColorController documentation](/tools/color-controller#supported-color-formats).
82+
3983
**Please note for the following formats: HSV, HSVA, HSL, HSLA**
84+
4085
When using the HSL or HSV formats, and a color's value (in HSV) is set to 0, or its luminosity (in HSL) is set to 0 or 1, the hue and saturation values may not be preserved by the element's `color` property. This is detailed in the [colorjs documentation](https://colorjs.io/docs/). Seperately, the element's `value` property is directly managed by the hue as represented in the interface.
4186

42-
## Default
87+
### Accessibility
4388

44-
```html
45-
<sp-color-slider></sp-color-slider>
46-
```
89+
The `<sp-color-slider>` is rendered with appropriate ARIA attributes to ensure accessibility:
4790

48-
### Vertical
91+
- Uses native `input[type="range"]` element with implicit "slider" role
92+
- Provides value text announcements for screen readers
93+
- Supports full keyboard navigation
4994

50-
```html
51-
<sp-color-slider vertical></sp-color-slider>
52-
```
95+
#### Accessible Labels
5396

54-
### Disabled
97+
The color slider includes an accessible label that describes what the slider controls. By default, the label is set to "hue", but you can customize it using the `label` attribute:
5598

5699
```html
57-
<sp-color-slider disabled></sp-color-slider>
100+
<!-- Default label -->
101+
<sp-color-slider></sp-color-slider>
102+
103+
<!-- Custom label -->
104+
<sp-color-slider label="Color hue"></sp-color-slider>
105+
<sp-color-slider label="Saturation level"></sp-color-slider>
58106
```
107+
108+
The label serves several important accessibility purposes:
109+
110+
- **Screen Reader Announcements**: Screen readers announce the label when the slider receives focus, helping users understand what they're adjusting
111+
- **ARIA Labeling**: The label is used as the `aria-label` attribute on the internal range input
112+
- **Context for Value Changes**: When the slider value changes, screen readers announce both the current value and the label for context
113+
114+
For example, when a user focuses on a color slider with `label="Color hue"`, screen readers will announce something like "Color hue slider, 180 degrees" to provide clear context about what the control does and its current value.
115+
116+
#### Keyboard Navigation
117+
118+
<sp-table>
119+
<sp-table-head>
120+
<sp-table-head-cell>Key</sp-table-head-cell>
121+
<sp-table-head-cell>Action</sp-table-head-cell>
122+
</sp-table-head>
123+
<sp-table-body>
124+
<sp-table-row>
125+
<sp-table-cell><kbd>Arrow Left</kbd>/<kbd>Arrow Down</kbd></sp-table-cell>
126+
<sp-table-cell>Decreases the hue value</sp-table-cell>
127+
</sp-table-row>
128+
<sp-table-row>
129+
<sp-table-cell><kbd>Arrow Right</kbd>/<kbd>Arrow Up</kbd></sp-table-cell>
130+
<sp-table-cell>Increases the hue value</sp-table-cell>
131+
</sp-table-row>
132+
<sp-table-row>
133+
<sp-table-cell><kbd>Shift + Arrow Left</kbd>/<kbd>Shift + Arrow Down</kbd></sp-table-cell>
134+
<sp-table-cell>Decreases the hue value by a larger step (10x)</sp-table-cell>
135+
</sp-table-row>
136+
<sp-table-row>
137+
<sp-table-cell><kbd>Shift + Arrow Right</kbd>/<kbd>Shift + Arrow Up</kbd></sp-table-cell>
138+
<sp-table-cell>Increases the hue value by a larger step (10x)</sp-table-cell>
139+
</sp-table-row>
140+
<sp-table-row>
141+
<sp-table-cell><kbd>Page Down</kbd></sp-table-cell>
142+
<sp-table-cell>Decreases the hue value by a larger step(10% of total value)</sp-table-cell>
143+
</sp-table-row>
144+
<sp-table-row>
145+
<sp-table-cell><kbd>Page Up</kbd></sp-table-cell>
146+
<sp-table-cell>Increases the hue value by a larger step(10% of total value)</sp-table-cell>
147+
</sp-table-row>
148+
<sp-table-row>
149+
<sp-table-cell><kbd>Home</kbd></sp-table-cell>
150+
<sp-table-cell>Sets the hue to minimum value (0)</sp-table-cell>
151+
</sp-table-row>
152+
<sp-table-row>
153+
<sp-table-cell><kbd>End</kbd></sp-table-cell>
154+
<sp-table-cell>Sets the hue to maximum value (360)</sp-table-cell>
155+
</sp-table-row>
156+
</sp-table-body>
157+
</sp-table>

0 commit comments

Comments
 (0)