Skip to content

Commit 4663b91

Browse files
authored
feat(ui5-tree): implement acc spec (#2636)
Changes: - Tooltip for the expand/collapse icon is added - Tree item is now announced - Selected state is now announced - Announced level is fixed - Translation for LIST_ITEM_SELECTED is fixed - Tree view is now read out once. Fixes #2465
1 parent 3e684b4 commit 4663b91

File tree

9 files changed

+58
-5
lines changed

9 files changed

+58
-5
lines changed

packages/main/src/List.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<ul id="{{_id}}-listUl"
2222
class="ui5-list-ul"
23-
role="{{role}}"
23+
role="{{accRole}}"
2424
aria-label="{{ariaLabelТxt}}"
2525
aria-labelledby="{{ariaLabelledBy}}"
2626
aria-multiselectable="{{isMultiSelect}}"

packages/main/src/List.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const metadata = {
195195
* @defaultvalue "listbox"
196196
* @since 1.0.0-rc.9
197197
*/
198-
role: {
198+
accRole: {
199199
type: String,
200200
defaultValue: "listbox",
201201
},

packages/main/src/ListItem.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
role="{{_accInfo.role}}"
1616
aria-expanded="{{_accInfo.ariaExpanded}}"
1717
aria-level="{{_accInfo.ariaLevel}}"
18+
aria-labelledby="{{_id}}-invisibleText {{_id}}-content"
1819
style="list-style-type: none;"
1920
>
2021
{{> listItemPreContent}}
@@ -43,6 +44,8 @@
4344
{{#if placeSelectionElementAfter}}
4445
{{> selectionElement}}
4546
{{/if}}
47+
48+
<span id="{{_id}}-invisibleText" class="ui5-hidden-text">{{_accInfo.listItemAriaLabel}}</span>
4649
</li>
4750

4851
{{#*inline "listItemPreContent"}}{{/inline}}

packages/main/src/ListItem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class ListItem extends ListItemBase {
311311
ariaExpanded: undefined,
312312
ariaLevel: undefined,
313313
ariaLabel: this.i18nBundle.getText(ARIA_LABEL_LIST_ITEM_CHECKBOX),
314+
listItemAriaLabel: undefined,
314315
};
315316
}
316317

packages/main/src/Tree.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.headerText="{{headerText}}"
44
.footerText="{{footerText}}"
55
.noDataText="{{noDataText}}"
6-
.role="{{_role}}"
6+
.accRole="{{_role}}"
77
@ui5-item-click="{{_onListItemClick}}"
88
@ui5-item-delete="{{_onListItemDelete}}"
99
@ui5-selection-change="{{_onListSelectionChange}}"

packages/main/src/TreeListItem.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{{>include "./ListItem.hbs"}}
22

33
{{#*inline "listItemPreContent"}}
4-
<div class="ui5-li-tree-toggle-box" style="padding-left: {{effectiveLevel}}rem; padding-left: calc(var(--_ui5-tree-indent-step) * {{effectiveLevel}});">
4+
<div
5+
class="ui5-li-tree-toggle-box"
6+
style="padding-left: {{effectiveLevel}}rem; padding-left: calc(var(--_ui5-tree-indent-step) * {{effectiveLevel}});"
7+
>
58
{{#if _showToggleButtonBeginning}}
69
<ui5-icon
710
class="ui5-li-tree-toggle-icon"
811
name="{{_toggleIconName}}"
12+
show-tooltip
13+
accessible-name="{{iconAccessibleName}}"
914
@click="{{_toggleClick}}"
1015
></ui5-icon>
1116
{{/if}}

packages/main/src/TreeListItem.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
22
import { isLeft, isRight } from "@ui5/webcomponents-base/dist/Keys.js";
3+
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
34
import ListItem from "./ListItem.js";
45
import Icon from "./Icon.js";
56
import "@ui5/webcomponents-icons/dist/navigation-right-arrow.js";
67
import "@ui5/webcomponents-icons/dist/navigation-down-arrow.js";
8+
import {
9+
TREE_ITEM_ARIA_LABEL,
10+
TREE_ITEM_EXPAND_NODE,
11+
TREE_ITEM_COLLAPSE_NODE,
12+
LIST_ITEM_SELECTED,
13+
} from "./generated/i18n/i18n-defaults.js";
714

815
// Template
916
import TreeListItemTemplate from "./generated/templates/TreeListItemTemplate.lit.js";
@@ -16,6 +23,7 @@ import treeListItemCss from "./generated/themes/TreeListItem.css.js";
1623
*/
1724
const metadata = {
1825
tag: "ui5-li-tree",
26+
languageAware: true,
1927
properties: /** @lends sap.ui.webcomponents.main.TreeListItem.prototype */ {
2028

2129
/**
@@ -175,6 +183,12 @@ class TreeListItem extends ListItem {
175183
];
176184
}
177185

186+
constructor() {
187+
super();
188+
189+
this.i18nBundle = getI18nBundle("@ui5/webcomponents");
190+
}
191+
178192
onBeforeRendering() {
179193
this.actionable = false;
180194
}
@@ -214,6 +228,7 @@ class TreeListItem extends ListItem {
214228
role: "treeitem",
215229
ariaExpanded: this.showToggleButton ? this.expanded : undefined,
216230
ariaLevel: this.level,
231+
listItemAriaLabel: this.ariaLabelText,
217232
};
218233
}
219234

@@ -241,6 +256,24 @@ class TreeListItem extends ListItem {
241256
}
242257
}
243258
}
259+
260+
get ariaLabelText() {
261+
let text = this.i18nBundle.getText(TREE_ITEM_ARIA_LABEL);
262+
263+
if (this.selected) {
264+
text += ` ${this.i18nBundle.getText(LIST_ITEM_SELECTED)}`;
265+
}
266+
267+
return text;
268+
}
269+
270+
get iconAccessibleName() {
271+
return this.expanded ? this.i18nBundle.getText(TREE_ITEM_COLLAPSE_NODE) : this.i18nBundle.getText(TREE_ITEM_EXPAND_NODE);
272+
}
273+
274+
static async onDefine() {
275+
await fetchI18nBundle("@ui5/webcomponents");
276+
}
244277
}
245278

246279
TreeListItem.define();

packages/main/src/i18n/messagebundle.properties

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ LINK_EMPHASIZED=Emphasized
266266
LIST_ITEM_POSITION=List item {0} of {1}
267267

268268
#XACT: ARIA announcement for the list item selection.
269-
LIST_ITEM_SELECTED=Is Selected
269+
LIST_ITEM_SELECTED=Selected
270270

271271
#XBUT: List Multi Selection Mode Checkbox aria-label text
272272
ARIA_LABEL_LIST_ITEM_CHECKBOX = Multiple Selection mode.
@@ -358,6 +358,15 @@ TOKENIZER_ARIA_LABEL=Tokenizer
358358
#XFLD: Remove label for Tokenizer's Dialog on phone
359359
TOKENIZER_POPOVER_REMOVE=Remove
360360

361+
#XACT: Label text for TreeListItem
362+
TREE_ITEM_ARIA_LABEL=Tree Item
363+
364+
#XTOL: tooltip for expand icon in a tree item
365+
TREE_ITEM_EXPAND_NODE=Expand Node
366+
367+
#XTOL: tooltip for collapse icon in a tree item
368+
TREE_ITEM_COLLAPSE_NODE=Collapse Node
369+
361370
#XTOL: text that is appended to the tooltips of input fields etc. which are marked to have an error
362371
VALUE_STATE_ERROR=Invalid entry
363372

packages/main/src/themes/TreeListItem.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "./InvisibleTextStyles.css";
2+
13
:host(:not([hidden])) {
24
display: block;
35
cursor: pointer;

0 commit comments

Comments
 (0)