Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-select): improve accessibility #2238

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/main/src/Select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
id="{{_id}}-select"
role="button"
aria-haspopup="listbox"
aria-label="{{ariaLabelText}}"
aria-labelledby="{{_id}}-label"
aria-labelledby="{{_id}}-labelText"
aria-describedby="{{valueStateTextId}}"
aria-disabled="{{isDisabled}}"
aria-required="{{required}}"
aria-expanded="{{_isPickerOpen}}"
aria-roledescription="{{selectRoleDescription}}"
aria-controls="{{_id}}-select-list"
aria-activedescendant="{{selectedListItem}}-li"
@keydown="{{_onkeydown}}"
@keyup="{{_onkeyup}}"
@focusin="{{_onfocusin}}"
Expand All @@ -27,6 +30,7 @@
dir="{{effectiveDir}}"
></ui5-icon>

<span id="{{_id}}-labelText" class="ui5-hidden-text">{{ariaLabelText}} {{_text}}</span>
{{#if hasValueState}}
<span id="{{_id}}-valueStateDesc" class="ui5-hidden-text">{{valueStateText}}</span>
{{/if}}
Expand Down
11 changes: 11 additions & 0 deletions packages/main/src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
VALUE_STATE_ERROR,
VALUE_STATE_WARNING,
INPUT_SUGGESTIONS_TITLE,
SELECT_ROLE_DESCRIPTION,
} from "./generated/i18n/i18n-defaults.js";
import Option from "./Option.js";
import Label from "./Label.js";
Expand Down Expand Up @@ -361,6 +362,7 @@ class Select extends UI5Element {
value: opt.value,
textContent: opt.textContent,
id: opt._id,
index: index + 1,
};
});

Expand Down Expand Up @@ -533,6 +535,11 @@ class Select extends UI5Element {
this.fireEvent("selected-item-changed");
}

get selectedListItem() {
const selectedItem = this._syncedOptions.find(item => item.selected);
return selectedItem && selectedItem.id;
}

get valueStateTextMappings() {
const i18nBundle = this.i18nBundle;

Expand Down Expand Up @@ -560,6 +567,10 @@ class Select extends UI5Element {
return this.disabled || undefined;
}

get selectRoleDescription() {
return this.i18nBundle.getText(SELECT_ROLE_DESCRIPTION);
}

get _headerTitleText() {
return this.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
}
Expand Down
18 changes: 16 additions & 2 deletions packages/main/src/SelectPopover.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@
{{/if}}
{{/unless}}

<ui5-list mode="SingleSelectAuto" separators="None" @keydown="{{_handlePickerKeydown}}" @ui5-selection-change="{{_handleSelectionChange}}" @ui5-item-press="{{_handleItemPress}}">
<ui5-list
id="{{_id}}-select-list"
mode="SingleSelectAuto"
separators="None"
@keydown="{{_handlePickerKeydown}}"
@ui5-selection-change="{{_handleSelectionChange}}"
@ui5-item-press="{{_handleItemPress}}"
>
{{#each _syncedOptions}}
<ui5-li ?selected="{{this.selected}}" icon="{{this.icon}}" id="{{this.id}}-li">
<ui5-li
id="{{this.id}}-li"
icon="{{this.icon}}"
?selected="{{this.selected}}"
?aria-selected="{{this.selected}}"
aria-setsize="{{../_syncedOptions.length}}"
aria-posinset="{{this.index}}"
>
{{this.textContent}}
</ui5-li>
{{/each}}
Expand Down
3 changes: 3 additions & 0 deletions packages/main/src/i18n/messagebundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ RATING_INDICATOR_TEXT=Rating Indicator
#XACT: ARIA description for the segmented button
SEGMENTEDBUTTON_ARIA_DESCRIPTION=Segmented button

#XACT: ARIA announcement for the Select`s roledescription attribute
SELECT_ROLE_DESCRIPTION=Select

#XACT: ARIA announcement for the switch on
SWITCH_ON=On

Expand Down