Skip to content

Commit e8d9768

Browse files
hunterloftisWestbrook
authored andcommitted
feat(color-area): separate X and Y aria labels to improve accessibility
1 parent c89396c commit e8d9768

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

packages/color-area/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ An `<sp-color-area>`’s height and width can be customized appropriately for it
6363
height: var(--spectrum-global-dimension-size-900)"
6464
></sp-color-area>
6565
```
66+
67+
## Labels
68+
69+
An `<sp-color-area>` renders accessible labels for each axis: _"saturation"_ and _"luminosity"_.
70+
Specify `label-x` and `label-y` attributes to override these defaults.
71+
72+
The `label` attribute is **deprecated** in favor of separately labeling each axis.
73+
74+
```html
75+
<sp-color-area
76+
label-x="Color intensity"
77+
label-y="Color brightness"
78+
></sp-color-area>
79+
```

packages/color-area/src/ColorArea.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ export class ColorArea extends SpectrumElement {
4949
public focused = false;
5050

5151
@property({ type: String })
52-
public label = 'saturation and luminosity';
52+
public label: string | undefined;
53+
54+
@property({ type: String, attribute: 'label-x' })
55+
public labelX = 'saturation';
56+
57+
@property({ type: String, attribute: 'label-y' })
58+
public labelY = 'luminosity';
5359

5460
@query('.handle')
5561
private handle!: ColorHandle;
@@ -498,7 +504,7 @@ export class ColorArea extends SpectrumElement {
498504
type="range"
499505
class="slider"
500506
name="x"
501-
aria-label=${this.label}
507+
aria-label=${this.label ?? this.labelX}
502508
min="0"
503509
max="1"
504510
step=${this.step}
@@ -513,7 +519,7 @@ export class ColorArea extends SpectrumElement {
513519
type="range"
514520
class="slider"
515521
name="y"
516-
aria-label=${this.label}
522+
aria-label=${this.label ?? this.labelY}
517523
min="0"
518524
max="1"
519525
step=${this.step}

packages/color-area/test/color-area.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,33 @@ describe('ColorArea', () => {
9797
});
9898
expect(document.activeElement, 'before input again').to.equal(input1);
9999
});
100+
it('provides separate aria-labels for X and Y inputs', async () => {
101+
const el = await fixture<ColorArea>(
102+
html`
103+
<sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
104+
`
105+
);
106+
const inputX = el.shadowRoot.querySelector('input[name="x"]');
107+
const inputY = el.shadowRoot.querySelector('input[name="y"]');
108+
109+
expect(inputX?.getAttribute('aria-label')).to.equal('saturation');
110+
expect(inputY?.getAttribute('aria-label')).to.equal('luminosity');
111+
});
112+
it('overrides both X and Y labels with a provided "label" attribute', async () => {
113+
const el = await fixture<ColorArea>(
114+
html`
115+
<sp-color-area
116+
color="hsl(100, 50%, 50%)"
117+
label="something custom"
118+
></sp-color-area>
119+
`
120+
);
121+
const inputX = el.shadowRoot.querySelector('input[name="x"]');
122+
const inputY = el.shadowRoot.querySelector('input[name="y"]');
123+
124+
expect(inputX?.getAttribute('aria-label')).to.equal('something custom');
125+
expect(inputY?.getAttribute('aria-label')).to.equal('something custom');
126+
});
100127
it('accepts "color" values as hsl', async () => {
101128
const el = await fixture<ColorArea>(
102129
html`

0 commit comments

Comments
 (0)