Skip to content

Commit 927abf6

Browse files
authored
fix(ui5-time-picker): accessibility improved (#3162)
The ui5-time-picker and ui5-duration picker inner input elements and wheel sliders now have aria properties set according to the screen reader specification. Fixes #3010
1 parent 3b930af commit 927abf6

File tree

6 files changed

+73
-10
lines changed

6 files changed

+73
-10
lines changed

packages/main/src/DurationPicker.js

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
22
import "@ui5/webcomponents-icons/dist/fob-watch.js";
33
import TimePickerBase from "./TimePickerBase.js";
44

5+
import {
6+
DURATION_INPUT_DESCRIPTION,
7+
} from "./generated/i18n/i18n-defaults.js";
8+
59
/**
610
* @public
711
*/
@@ -286,6 +290,21 @@ class DurationPicker extends TimePickerBase {
286290
get maxSeconds() {
287291
return parseInt(this.maxValue.split(":")[2]);
288292
}
293+
294+
get dateAriaDescription() {
295+
return this.i18nBundle.getText(DURATION_INPUT_DESCRIPTION);
296+
}
297+
298+
get accInfo() {
299+
return {
300+
"ariaRoledescription": this.dateAriaDescription,
301+
"ariaHasPopup": "dialog",
302+
"ariaAutoComplete": "none",
303+
"role": "combobox",
304+
"ariaControls": `${this._id}-responsive-popover`,
305+
"ariaExpanded": this.isOpen(),
306+
};
307+
}
289308
}
290309

291310
DurationPicker.define();

packages/main/src/TimePicker.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
?disabled="{{disabled}}"
77
?readonly="{{readonly}}"
88
value-state="{{valueState}}"
9+
._inputAccInfo="{{accInfo}}"
910
@click="{{_handleInputClick}}"
1011
@ui5-change="{{_handleInputChange}}"
1112
@ui5-input="{{_handleInputLiveChange}}"

packages/main/src/TimePicker.js

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
22
import getCachedLocaleDataInstance from "@ui5/webcomponents-localization/dist/getCachedLocaleDataInstance.js";
33
import TimePickerBase from "./TimePickerBase.js";
44

5+
import {
6+
TIMEPICKER_INPUT_DESCRIPTION,
7+
} from "./generated/i18n/i18n-defaults.js";
8+
59
/**
610
* @public
711
*/
@@ -140,6 +144,21 @@ class TimePicker extends TimePickerBase {
140144
get dateValue() {
141145
return this.getFormat().parse(this._effectiveValue);
142146
}
147+
148+
get accInfo() {
149+
return {
150+
"ariaRoledescription": this.dateAriaDescription,
151+
"ariaHasPopup": "dialog",
152+
"ariaAutoComplete": "none",
153+
"role": "combobox",
154+
"ariaControls": `${this._id}-responsive-popover`,
155+
"ariaExpanded": this.isOpen(),
156+
};
157+
}
158+
159+
get dateAriaDescription() {
160+
return this.i18nBundle.getText(TIMEPICKER_INPUT_DESCRIPTION);
161+
}
143162
}
144163

145164
TimePicker.define();

packages/main/src/WheelSlider.hbs

+15-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@
1919
<div id="{{this._id}}--selection-frame" class="ui5-wheelslider-selection-frame"></div>
2020
<div id="{{this._id}}--wrapper" class="ui5-wheelslider-wrapper">
2121
{{#if expanded}}
22-
<ul id="{{this._id}}--items-list">
22+
<ul id="{{this._id}}--items-list" role="listbox" aria-label="{{label}}">
2323
{{#each _itemsToShow}}
24-
<li class="ui5-wheelslider-item" data-item-index="{{@index}}" style="list-style-type: none;">{{this}}</li>
24+
<li class="ui5-wheelslider-item"
25+
data-item-index="{{@index}}"
26+
role="option"
27+
aria-selected="{{this.selected}}"
28+
style="list-style-type: none;">
29+
{{this.value}}
30+
</li>
2531
{{/each}}
2632
</ul>
2733
{{else}}
28-
<ul id="{{this._id}}--items-list">
29-
<li class="ui5-wheelslider-item" style="list-style-type: none;">{{value}}</li>
34+
<ul id="{{this._id}}--items-list" role="listbox" aria-label="{{label}}">
35+
<li class="ui5-wheelslider-item"
36+
role="option"
37+
aria-selected="true"
38+
style="list-style-type: none;">
39+
{{value}}
40+
</li>
3041
</ul>
3142
{{/if}}
3243
</div>

packages/main/src/WheelSlider.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const metadata = {
7676
},
7777

7878
_itemsToShow: {
79-
type: String,
79+
type: Object,
8080
multiple: true,
8181
},
8282

@@ -248,7 +248,7 @@ class WheelSlider extends UI5Element {
248248

249249
offsetIndex = Math.round(scrollWhere / cellSizeInPx);
250250

251-
if (this.value === this._itemsToShow[offsetIndex]) {
251+
if (this.value === this._itemsToShow[offsetIndex].value) {
252252
return;
253253
}
254254

@@ -259,7 +259,7 @@ class WheelSlider extends UI5Element {
259259
}
260260
}
261261

262-
this.value = this._itemsToShow[offsetIndex];
262+
this.value = this._itemsToShow[offsetIndex].value;
263263
this._currentElementIndex = offsetIndex;
264264
}
265265

@@ -311,14 +311,21 @@ class WheelSlider extends UI5Element {
311311
}
312312

313313
_buildItemsToShow() {
314-
this._itemsToShow = this._items;
314+
let itemsToShow = this._items;
315315
if (this.cyclic) {
316-
if (this._itemsToShow.length < this._items.length * this._timesMultipliedOnCyclic()) {
316+
if (itemsToShow.length < this._items.length * this._timesMultipliedOnCyclic()) {
317317
for (let i = 0; i < this._timesMultipliedOnCyclic(); i++) {
318-
this._itemsToShow = this._itemsToShow.concat(this._items);
318+
itemsToShow = itemsToShow.concat(this._items);
319319
}
320320
}
321321
}
322+
323+
this._itemsToShow = itemsToShow.map(value => {
324+
return {
325+
value,
326+
"selected": (value === this.value),
327+
};
328+
});
322329
}
323330

324331
_handleArrayBorderReached(currentIndex) {

packages/main/src/i18n/messagebundle.properties

+6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ TIMEPICKER_SUBMIT_BUTTON=OK
205205
#XFLD: Timepicker popover button
206206
TIMEPICKER_CANCEL_BUTTON=Cancel
207207

208+
#XACT: Aria information for the Time Picker
209+
TIMEPICKER_INPUT_DESCRIPTION=Time Input
210+
211+
#XACT: Aria information for the Duration Picker
212+
DURATION_INPUT_DESCRIPTION=Duration Input
213+
208214
#XFLD: DateTimePicker popover button
209215
DATETIME_PICKER_DATE_BUTTON=Date
210216

0 commit comments

Comments
 (0)