Skip to content

Commit ede3635

Browse files
authored
feat(ui5-select): implement accessibility spec (#1485)
1 parent f337d47 commit ede3635

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

packages/main/src/Select.hbs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<div
22
class="ui5-select-root"
3-
tabindex="{{tabIndex}}"
43
dir="{{dir}}"
4+
tabindex="{{tabIndex}}"
5+
id="{{_id}}-select"
6+
role="button"
7+
aria-haspopup="listbox"
8+
aria-labelledby="{{_id}}-label"
9+
aria-describedby="{{valueStateTextId}}"
10+
aria-disabled="{{isDisabled}}"
511
@keydown="{{_onkeydown}}"
612
@keyup="{{_onkeyup}}"
713
@focusin="{{_onfocusin}}"
814
@focusout="{{_onfocusout}}"
915
@click="{{_toggleRespPopover}}"
1016
>
1117
<div class="ui5-select-label-root">
12-
<ui5-label>{{_text}}</ui5-label>
18+
<ui5-label id="{{_id}}-label" for="{{_id}}-select">{{_text}}</ui5-label>
1319
</div>
1420

1521
<ui5-icon
@@ -19,5 +25,8 @@
1925
dir="{{dir}}"
2026
></ui5-icon>
2127

28+
{{#if hasValueState}}
29+
<span id="{{_id}}-valueStateDesc" class="ui5-hidden-text">{{valueStateText}}</span>
30+
{{/if}}
2231
<slot name="formSupport"></slot>
2332
</div>

packages/main/src/Select.js

+31
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import "@ui5/webcomponents-icons/dist/icons/slim-arrow-down.js";
1515
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
1616
import "@ui5/webcomponents-icons/dist/icons/decline.js";
1717
import {
18+
VALUE_STATE_SUCCESS,
19+
VALUE_STATE_INFORMATION,
20+
VALUE_STATE_ERROR,
21+
VALUE_STATE_WARNING,
1822
INPUT_SUGGESTIONS_TITLE,
1923
} from "./generated/i18n/i18n-defaults.js";
2024
import Label from "./Label.js";
@@ -424,6 +428,33 @@ class Select extends UI5Element {
424428
}
425429
}
426430

431+
get valueStateTextMappings() {
432+
const i18nBundle = this.i18nBundle;
433+
434+
return {
435+
"Success": i18nBundle.getText(VALUE_STATE_SUCCESS),
436+
"Information": i18nBundle.getText(VALUE_STATE_INFORMATION),
437+
"Error": i18nBundle.getText(VALUE_STATE_ERROR),
438+
"Warning": i18nBundle.getText(VALUE_STATE_WARNING),
439+
};
440+
}
441+
442+
get valueStateText() {
443+
return this.valueStateTextMappings[this.valueState];
444+
}
445+
446+
get hasValueState() {
447+
return this.valueState !== ValueState.None;
448+
}
449+
450+
get valueStateTextId() {
451+
return this.hasValueState ? `${this._id}-valueStateDesc` : undefined;
452+
}
453+
454+
get isDisabled() {
455+
return this.disabled || undefined;
456+
}
457+
427458
get _headerTitleText() {
428459
return this.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
429460
}

0 commit comments

Comments
 (0)