Skip to content

Commit

Permalink
fix(ui5-tree): accessibility improvements (#2671)
Browse files Browse the repository at this point in the history
Added new aria-posinset and aria-setsize attributes to each element. Now, screen reader will know the count of the items on the same level and the position of the current active item.

Fixes: #2553
  • Loading branch information
nnaydenow authored and ilhan007 committed Jan 13, 2021
1 parent 25a6f99 commit 46c02b9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/main/src/ListItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
role="{{_accInfo.role}}"
aria-expanded="{{_accInfo.ariaExpanded}}"
aria-level="{{_accInfo.ariaLevel}}"
aria-posinset="{{_accInfo.posinset}}"
aria-setsize="{{_accInfo.setsize}}"
aria-labelledby="{{_id}}-invisibleText {{_id}}-content"
style="list-style-type: none;"
>
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/Tree.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
.expanded="{{this.treeItem.expanded}}"
.selected="{{this.treeItem.selected}}"
.showToggleButton="{{this.treeItem.requiresToggleButton}}"
._posinset="{{this.posinset}}"
._setsize="{{this.size}}"
@ui5-toggle="{{../_onListItemToggle}}"
@ui5-step-in="{{../_onListItemStepIn}}"
@ui5-step-out="{{../_onListItemStepOut}}"
Expand Down
4 changes: 3 additions & 1 deletion packages/main/src/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,11 @@ const walkTree = (el, level, callback) => {
};

const buildTree = (el, level, result) => {
el.items.forEach(item => {
el.items.forEach((item, index) => {
const listItem = {
treeItem: item,
size: el.items.length,
posinset: index + 1,
level,
};

Expand Down
22 changes: 22 additions & 0 deletions packages/main/src/TreeListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ const metadata = {
type: Boolean,
},

/**
* @private
* @since 1.0.0-rc.11
*/
_setsize: {
type: Integer,
defaultValue: 1,
noAttribute: true,
},

/**
* @private
* @since 1.0.0-rc.11
*/
_posinset: {
type: Integer,
defaultValue: 1,
noAttribute: true,
},

},
slots: /** @lends sap.ui.webcomponents.main.TreeListItem.prototype */ {
/**
Expand Down Expand Up @@ -228,6 +248,8 @@ class TreeListItem extends ListItem {
role: "treeitem",
ariaExpanded: this.showToggleButton ? this.expanded : undefined,
ariaLevel: this.level,
posinset: this._posinset,
setsize: this._setsize,
listItemAriaLabel: this.ariaLabelText,
};
}
Expand Down

0 comments on commit 46c02b9

Please sign in to comment.