Skip to content

Commit

Permalink
WEBUI-785: nuxeo-document-tree icon needs to be focusable (#2414)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgupta-hyland authored Jan 16, 2025
1 parent e41d781 commit 4b13669
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion elements/nuxeo-document-tree/nuxeo-document-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ Polymer({
cursor: pointer;
}
[toggle]:focus {
outline: 2px solid black;
outline-offset: 0.2px;
border-radius: 3px;
box-shadow: 0 0 3px black;
background-color: rgba(0, 0, 0, 0);
}
.parents {
line-height: 1.5em;
}
Expand Down Expand Up @@ -191,7 +199,16 @@ Polymer({
<div role="treeitem" aria-expanded="[[opened]]">
<template class="flex" is="dom-if" if="[[!isLeaf]]">
<paper-spinner active$="[[loading]]" aria-hidden="true"></paper-spinner>
<iron-icon icon="[[_expandIcon(opened)]]" toggle hidden$="[[loading]]" aria-hidden="true"></iron-icon>
<iron-icon
icon="[[_expandIcon(opened)]]"
toggle
hidden$="[[loading]]"
tabindex="0"
role="button"
aria-hidden="false"
aria-label="Toggle expand/collapse"
on-keydown="_handleKeydown"
></iron-icon>
<template is="dom-if" if="[[loading]]">
<span class="loaddata" aria-live="polite">[[_loading(loading)]]</span>
</template>
Expand Down Expand Up @@ -306,6 +323,27 @@ Polymer({
}
},

_handleKeydown(event) {
const icon = event.target;
const treeItem = icon.closest('[role="treeitem"]');
if (event.key === 'Enter' || event.key === ' ' || event.key === 'ArrowDown') {
// Toggle aria-expanded state
const expanded = treeItem.getAttribute('aria-expanded') === 'true';
treeItem.setAttribute('aria-expanded', !expanded);
// Manually trigger the click event on the chevron icon
icon.click();
// Dispatch custom event for external handling
this.dispatchEvent(
new CustomEvent('tree-node-toggled', {
detail: { expanded: !expanded, target: treeItem },
bubbles: true,
composed: true,
}),
);
event.preventDefault(); // Prevent default scrolling or focus behavior
}
},

_currentDocumentChanged() {
const doc = this.currentDocument;
if (doc && doc.path && doc.path.startsWith(this.rootDocPath)) {
Expand Down

0 comments on commit 4b13669

Please sign in to comment.