File tree Expand file tree Collapse file tree 3 files changed +50
-3
lines changed Expand file tree Collapse file tree 3 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -63,3 +63,17 @@ An `<sp-color-area>`’s height and width can be customized appropriately for it
63
63
height : var (--spectrum-global-dimension-size-900 ) "
64
64
></sp-color-area >
65
65
```
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
+ ```
Original file line number Diff line number Diff line change @@ -49,7 +49,13 @@ export class ColorArea extends SpectrumElement {
49
49
public focused = false ;
50
50
51
51
@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' ;
53
59
54
60
@query ( '.handle' )
55
61
private handle ! : ColorHandle ;
@@ -498,7 +504,7 @@ export class ColorArea extends SpectrumElement {
498
504
type ="range "
499
505
class ="slider "
500
506
name ="x "
501
- aria-label =${ this . label }
507
+ aria-label =${ this . label ?? this . labelX }
502
508
min ="0"
503
509
max="1"
504
510
step=${ this . step }
@@ -513,7 +519,7 @@ export class ColorArea extends SpectrumElement {
513
519
type ="range "
514
520
class ="slider "
515
521
name ="y "
516
- aria-label =${ this . label }
522
+ aria-label =${ this . label ?? this . labelY }
517
523
min ="0"
518
524
max="1"
519
525
step=${ this . step }
Original file line number Diff line number Diff line change @@ -97,6 +97,33 @@ describe('ColorArea', () => {
97
97
} ) ;
98
98
expect ( document . activeElement , 'before input again' ) . to . equal ( input1 ) ;
99
99
} ) ;
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
+ } ) ;
100
127
it ( 'accepts "color" values as hsl' , async ( ) => {
101
128
const el = await fixture < ColorArea > (
102
129
html `
You can’t perform that action at this time.
0 commit comments