Skip to content

Commit 849d052

Browse files
authored
fix(ui5-tree): accessibility improvements (#2671)
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
1 parent 32dd0ef commit 849d052

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

packages/main/src/ListItem.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
role="{{_accInfo.role}}"
1616
aria-expanded="{{_accInfo.ariaExpanded}}"
1717
aria-level="{{_accInfo.ariaLevel}}"
18+
aria-posinset="{{_accInfo.posinset}}"
19+
aria-setsize="{{_accInfo.setsize}}"
1820
aria-labelledby="{{_id}}-invisibleText {{_id}}-content"
1921
style="list-style-type: none;"
2022
>

packages/main/src/Tree.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
.expanded="{{this.treeItem.expanded}}"
2222
.selected="{{this.treeItem.selected}}"
2323
.showToggleButton="{{this.treeItem.requiresToggleButton}}"
24+
._posinset="{{this.posinset}}"
25+
._setsize="{{this.size}}"
2426
@ui5-toggle="{{../_onListItemToggle}}"
2527
@ui5-step-in="{{../_onListItemStepIn}}"
2628
@ui5-step-out="{{../_onListItemStepOut}}"

packages/main/src/Tree.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,11 @@ const walkTree = (el, level, callback) => {
349349
};
350350

351351
const buildTree = (el, level, result) => {
352-
el.items.forEach(item => {
352+
el.items.forEach((item, index) => {
353353
const listItem = {
354354
treeItem: item,
355+
size: el.items.length,
356+
posinset: index + 1,
355357
level,
356358
};
357359

packages/main/src/TreeListItem.js

+22
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ const metadata = {
9191
type: Boolean,
9292
},
9393

94+
/**
95+
* @private
96+
* @since 1.0.0-rc.11
97+
*/
98+
_setsize: {
99+
type: Integer,
100+
defaultValue: 1,
101+
noAttribute: true,
102+
},
103+
104+
/**
105+
* @private
106+
* @since 1.0.0-rc.11
107+
*/
108+
_posinset: {
109+
type: Integer,
110+
defaultValue: 1,
111+
noAttribute: true,
112+
},
113+
94114
},
95115
slots: /** @lends sap.ui.webcomponents.main.TreeListItem.prototype */ {
96116
/**
@@ -228,6 +248,8 @@ class TreeListItem extends ListItem {
228248
role: "treeitem",
229249
ariaExpanded: this.showToggleButton ? this.expanded : undefined,
230250
ariaLevel: this.level,
251+
posinset: this._posinset,
252+
setsize: this._setsize,
231253
listItemAriaLabel: this.ariaLabelText,
232254
};
233255
}

0 commit comments

Comments
 (0)