Skip to content

Commit 06e5aa1

Browse files
authored
fix(ui5-li-tree): fix aria-expanded value (#1894)
The aria-expanded attribute should not be set for non-expandable nodes. FIXES: #1892
1 parent 8f260f8 commit 06e5aa1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/main/src/TreeListItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class TreeListItem extends ListItem {
176176
get _accInfo() {
177177
return {
178178
role: "treeitem",
179-
ariaExpanded: this.expanded,
179+
ariaExpanded: this.showToggleButton ? this.expanded : undefined,
180180
ariaLevel: this.level,
181181
};
182182
}

packages/main/test/specs/Tree.spec.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,30 @@ describe("Tree has screen reader support", () => {
7171
it("List item acc attributes correct", () => {
7272
const tree = browser.$("#tree");
7373
const listItems = tree.shadow$$("ui5-li-tree");
74-
listItems.forEach(item => {
74+
75+
listItems.forEach((item, idx) => {
7576
const li = item.shadow$("li");
77+
const itemExpandable = item.getProperty("showToggleButton");
78+
const itemExpanded = item.getProperty("expanded");
79+
const liAriaExpanded = li.getAttribute("aria-expanded");
80+
81+
const ariaExpandedValues = {
82+
// (1) expandable: aria-expanded can be 'true' or 'false'
83+
"true": {
84+
"true" : "true",
85+
"false": "false",
86+
},
87+
// (2) not expandable: aria-expanded is null - not present
88+
"false": {
89+
"true" : null,
90+
"false": null,
91+
}
92+
};
7693

7794
assert.ok(li.getAttribute("role") === "treeitem", "List item role is correct");
7895
assert.ok(li.getAttribute("aria-level") === item.getAttribute("level"), "aria level is correct");
79-
assert.ok(li.getAttribute("aria-expanded") === item.getAttribute("expanded"), "aria expanded is correct");
96+
assert.equal(liAriaExpanded, ariaExpandedValues[itemExpandable][itemExpanded],
97+
"aria-expanded is correct.");
8098
});
8199

82100
});

0 commit comments

Comments
 (0)