Skip to content

Commit 7b02904

Browse files
committed
ENH Set aria-expanded attr on toggle
1 parent cea88c4 commit 7b02904

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

client/dist/js/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/legacy/LeftAndMain.Tree.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ const resetTabindexToCurrentPage = ($tree) => {
3737
}
3838
};
3939

40+
const updateTreeAriaExpanded = ($treeNode, expanded) => {
41+
if (!$treeNode || !$treeNode.length) {
42+
return;
43+
}
44+
45+
const ariaExpanded = expanded ? 'true' : 'false';
46+
47+
$treeNode
48+
.children('a[role="treeitem"][aria-expanded], strong[role="treeitem"][aria-expanded]')
49+
.attr('aria-expanded', ariaExpanded);
50+
$treeNode
51+
.children('.jstree-icon--arrow[role="button"]')
52+
.attr('aria-expanded', ariaExpanded);
53+
};
54+
4055
// this conditional check is so that we can unit test the functions above in this file without needing to
4156
// load in jquery.entwine
4257
if (typeof $.entwine === 'function') {
@@ -175,6 +190,17 @@ if (typeof $.entwine === 'function') {
175190
}
176191
resetTabindexToCurrentPage(self);
177192
})
193+
.on('open_node.jstree close_node.jstree', function(e, data) {
194+
var node = data && data.rslt ? data.rslt.obj : null;
195+
if ((!node || !$(node).length) && data && data.args && data.args.length) {
196+
node = data.args[0];
197+
}
198+
if ((!node || !$(node).length) && data && data.node) {
199+
node = data.node;
200+
}
201+
202+
updateTreeAriaExpanded($(node), e.type === 'open_node');
203+
})
178204
.on('keydown', function(e) {
179205
var key = e.key;
180206
var target = e.target;
@@ -719,4 +745,4 @@ if (typeof $.entwine === 'function') {
719745
});
720746
}
721747

722-
export { updateRovingTabindex, resetTabindexToCurrentPage };
748+
export { updateRovingTabindex, resetTabindexToCurrentPage, updateTreeAriaExpanded };

0 commit comments

Comments
 (0)