File tree 4 files changed +62
-0
lines changed
4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 5
5
id =" {{ _id }} -select"
6
6
role =" button"
7
7
aria-haspopup =" listbox"
8
+ aria-label =" {{ ariaLabelText }} "
8
9
aria-labelledby =" {{ _id }} -label"
9
10
aria-describedby =" {{ valueStateTextId }} "
10
11
aria-disabled =" {{ isDisabled }} "
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
} from "@ui5/webcomponents-base/dist/Keys.js" ;
13
13
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js" ;
14
14
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js" ;
15
+ import getEffectiveAriaLabelText from "@ui5/webcomponents-base/dist/util/getEffectiveAriaLabelText.js" ;
15
16
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js" ;
16
17
import "@ui5/webcomponents-icons/dist/icons/slim-arrow-down.js" ;
17
18
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js" ;
@@ -157,6 +158,31 @@ const metadata = {
157
158
type : Boolean ,
158
159
} ,
159
160
161
+ /**
162
+ * Defines the aria-label attribute for the select.
163
+ *
164
+ * @type {String }
165
+ * @since 1.0.0-rc.9
166
+ * @private
167
+ * @defaultvalue ""
168
+ */
169
+ ariaLabel : {
170
+ type : String ,
171
+ } ,
172
+
173
+ /**
174
+ * Receives id(or many ids) of the elements that label the select.
175
+ *
176
+ * @type {String }
177
+ * @defaultvalue ""
178
+ * @private
179
+ * @since 1.0.0-rc.9
180
+ */
181
+ ariaLabelledby : {
182
+ type : String ,
183
+ defaultValue : "" ,
184
+ } ,
185
+
160
186
_text : {
161
187
type : String ,
162
188
noAttribute : true ,
@@ -576,6 +602,10 @@ class Select extends UI5Element {
576
602
} ;
577
603
}
578
604
605
+ get ariaLabelText ( ) {
606
+ return getEffectiveAriaLabelText ( this ) ;
607
+ }
608
+
579
609
get valueStateMessageText ( ) {
580
610
return this . getSlottedNodes ( "valueStateMessage" ) . map ( el => el . cloneNode ( true ) ) ;
581
611
}
Original file line number Diff line number Diff line change @@ -75,6 +75,24 @@ <h2>Selection not cycling</h2>
75
75
< h2 > Change event counter holder</ h2 >
76
76
< ui5-input id ="inputResult "> </ ui5-input >
77
77
78
+ < section >
79
+ < h3 > Select aria-label and aria-labelledby</ h3 >
80
+ < span id ="infoText "> info text</ span >
81
+ < div >
82
+ < ui5-select id ="textAreaAriaLabel " aria-label ="Hello World ">
83
+ < ui5-option selected > First</ ui5-option >
84
+ < ui5-option selected > Second</ ui5-option >
85
+ < ui5-option selected > Third</ ui5-option >
86
+ </ ui5-select >
87
+
88
+ < ui5-select id ="textAreaAriaLabelledBy " aria-labelledby ="infoText ">
89
+ < ui5-option selected > One</ ui5-option >
90
+ < ui5-option selected > Two</ ui5-option >
91
+ < ui5-option selected > Three</ ui5-option >
92
+ </ ui5-select >
93
+ </ div >
94
+ </ section >
95
+
78
96
< section class ="ui5-content-density-compact ">
79
97
< h3 > Select in Compact</ h3 >
80
98
< div >
Original file line number Diff line number Diff line change @@ -293,4 +293,17 @@ describe("Select general interaction", () => {
293
293
294
294
assert . ok ( selectText . getHTML ( false ) . indexOf ( EXPECTED_SELECTION_TEXT2 ) !== - 1 , "Select label is correct." ) ;
295
295
} ) ;
296
+
297
+
298
+ it ( "Tests aria-label and aria-labelledby" , ( ) => {
299
+ const select1 = browser . $ ( "#textAreaAriaLabel" ) . shadow$ ( ".ui5-select-root" ) ;
300
+ const select2 = browser . $ ( "#textAreaAriaLabelledBy" ) . shadow$ ( ".ui5-select-root" ) ;
301
+ const EXPECTED_ARIA_LABEL1 = "Hello World" ;
302
+ const EXPECTED_ARIA_LABEL2 = "info text" ;
303
+
304
+ assert . strictEqual ( select1 . getAttribute ( "aria-label" ) , EXPECTED_ARIA_LABEL1 ,
305
+ "The aria-label is correctly set internally." ) ;
306
+ assert . strictEqual ( select2 . getAttribute ( "aria-label" ) , EXPECTED_ARIA_LABEL2 ,
307
+ "The aria-label is correctly set internally." ) ;
308
+ } ) ;
296
309
} ) ;
You can’t perform that action at this time.
0 commit comments