krautzource / aria-tree-walker

A lightweight walker for labeled ARIA trees
https://krautzource.github.io/aria-tree-walker/
Apache License 2.0
2 stars 0 forks source link

retest tabindex change on focusout #32

Open pkra opened 3 years ago

pkra commented 3 years ago

Looking at the APG patterns, they leave the tabindex as is when focus leaves the tree. Let's try that as it might help improve UX for revisiting a tree after exploration (cf. https://gitlab.gnome.org/GNOME/orca/-/issues/195#note_1065628).

pkra commented 3 years ago

It doesn't seem to change Orca's behavior; I don't recall how other ATs did - needs more testing.

pkra commented 3 years ago

After more testing, this doesn't seem to help much. Like Orca, NVDA is fine either way (Chrome, FF). JAWS is ok in Chrome but in Firefox, JAWS browse mode visits both the tree's label and active (tabindex=0) treeitem's label; sometimes visits the treeitem twice.

VoiceOver on Mac is a hot mess, I can't remember what it was like the last time but I feel it's about the same; both Safari and Chrome struggle in general and don't improve with the change.

pkra commented 3 years ago

We need clearer test instructions and documentation of results.

pkra commented 3 years ago

For the record, here's the diff of the rough implementation I tested:

diff --git a/lib/navigator.js b/lib/navigator.js
index 21472a0..f61f896 100644
--- a/lib/navigator.js
+++ b/lib/navigator.js
@@ -15,12 +15,10 @@ class navigator {
     this.tree = extractAbstractTree(node);
     this.node.addEventListener('keydown', this.move.bind(this));
     this.node.addEventListener('focusin', () => {
-      this.node.setAttribute('tabindex', '-1');
       this.highlight(true);
     });
     this.node.addEventListener('focusout', () => {
-      this.highlight(false);
-      this.node.setAttribute('tabindex', '0');
+      this.highlight(false, true);
     });
   }

@@ -69,7 +67,7 @@ class navigator {
     node.getAttribute('data-owns').split(' ').forEach(id => this.highlightSubtree(boolean, this.node.querySelector(`[data-owns-id="${id}"]`)));
   }

-  highlight(boolean) {
+  highlight(boolean, focusOut) {
     const activedescendant =
       this.active().name === this.node.getAttribute('data-owns-id')
         ? this.node
@@ -81,7 +79,7 @@ class navigator {
       activedescendant.focus();
     }
     if (boolean === false) {
-      activedescendant.setAttribute('tabindex', '-1');
+      if (!focusOut) activedescendant.setAttribute('tabindex', '-1');
       activedescendant.classList.remove('is-activedescendant');
     }
   }