Skip to content

Keyboard a11y structure - #787

Merged
Dananji merged 12 commits into
mainfrom
keyboard-a11y-structure
Apr 9, 2025
Merged

Keyboard a11y structure#787
Dananji merged 12 commits into
mainfrom
keyboard-a11y-structure

Conversation

@Dananji

@Dananji Dananji commented Mar 20, 2025

Copy link
Copy Markdown
Collaborator

Related issue: #766

Design pattern selected: TreeView (https://www.w3.org/WAI/ARIA/apg/patterns/treeview/). This pattern describes implementing accessible nested tree like structures in a UI.

The examples in this pattern, use <ul> and <li> HTML elements in a nested structure as needed to render the given information on the page.

By comparing the current StructuredNavigation component implement in Ramp, I noticed we have some unnecessary groupings at each nested level. This creates a complex DOM tree, which is a bit harder to understand and debug code-wise, and confusing for assistive technologies to interpret and present in an understandable manner.

Therefore, I refactored the way Ramp build the nested structures to mimic the example implementations in this design pattern. This replaces the unnecessarily complex DOM tree we were building with a much more simple nested list pattern.

With this change, List, ListItem, and SectionHeading sub-components (the building blocks of StructuredNavigation component) were replaced with a single sub-component called TreeNode which creates each leaf node and sub tree recursively avoiding unnecessary groupings.

Keyboard navigation was then implemented on top of this structure. And the way it works is as follows;

  • Once the user tabs into the StructuredNavigation component, they can use ArrowDown and ArrowUp keys to select actionable structure items (links and buttons).
  • When a timespan (a link) is selected pressing Enter key updates the player to the media-fragment linked for that timespan.
  • When a section (a button) is selected pressing either Enter or ArrowRight key updates the player to the media associated with the section.
    • While focused on a section, pressing ArrowLeft and ArrowRight keys respectively collapses and expands the collapsible structure related to that section.
  • Once the focus is within StructuredNavigation component, pressing tab again will move the keyboard focus to the next UI portion on the page. In the case of Ramp demo site; this is the Details tab next to StructuredNavigation component.
  • Once the focus is within StructuredNavigation component, pressing Shift+Tab will move the keyboard focus back to the StructuredNavigation container, and then pressing the key combination again move the focus the previous UI portion on the page. In the case of Ramp demo site; this is the Close/Expand all section button prior to structure.

@Dananji
Dananji force-pushed the keyboard-a11y-structure branch from 5231ddf to dfd0f96 Compare March 25, 2025 14:30
@cjcolvar

cjcolvar commented Mar 26, 2025

Copy link
Copy Markdown
Member

@Dananji Testing this out locally I'm getting errors when I try to click or activate a structure node by pressing Enter:

times is undefined
./src/services/ramp-hooks.js/useActiveStructure/handleClick<@http://localhost:3003/bundle.js:17279:17

Maybe this PR needs to be updated with similar changes to those in #784?

@Dananji

Dananji commented Mar 28, 2025

Copy link
Copy Markdown
Collaborator Author

@Dananji Testing this out locally I'm getting errors when I try to click or activate a structure node by pressing Enter:

times is undefined
./src/services/ramp-hooks.js/useActiveStructure/handleClick<@http://localhost:3003/bundle.js:17279:17

Maybe this PR needs to be updated with similar changes to those in #784?

Yes, I re-based this after #784 was merged, so it messed this work. I work on fixing it 👍

@cjcolvar

Copy link
Copy Markdown
Member

This is working for me now and an improvement to keyboard navigation! A couple things I noticed when testing:

  • Right / Left arrow will expand / collapse sections but right / left arrow anywhere else in the structure will + / - 5 sec to the current time. Maybe this is natural with a screen reader but this feels a bit odd needing to know what kind of node is focused in the structure as to how the the right / left arrow keys will work. Maybe a different way of thinking about this is should all nodes be able to be collapsed / expanded?
  • I was expecting space bar presses to click links similar to player controls which operate on space bar, enter, or click. (FWIW collapse / expand all sections button is also only activated by enter but I might expect space bar and right / left arrow keys to work there. Also Auto-advance only works with space bar but I might expect enter and right / left arrow keys to work there too.) When the structure is overflowing and scroll bars appear then space bar does a page down in the structure.

@Dananji

Dananji commented Mar 31, 2025

Copy link
Copy Markdown
Collaborator Author

Thank you for taking the time to test this @cjcolvar !

Right / Left arrow will expand / collapse sections but right / left arrow anywhere else in the structure will + / - 5 sec to the current time. Maybe this is natural with a screen reader but this feels a bit odd needing to know what kind of node is focused in the structure as to how the the right / left arrow keys will work. Maybe a different way of thinking about this is should all nodes be able to be collapsed / expanded?

I was following the Tree view pattern in W3C and according to that, when focused on end nodes (leaf nodes) the ArrowRight key is suppose to do nothing. But ArrowLeft should move the focus back to its parent node when focused on a child node (in this case leaf nodes).
I had missed the ArrowLeft keypress acton in this implementation. I will add this to the event handler on leaf nodes.

As for making all nodes being able to be collapsed/expanded; I'm sorry, I can't visualize how this is done on an end node (leaf node). Could you please clarify this?

Another solution I can think for this is to catch the ArrowRight event within the focused end node's event handlers and block it from reaching player hotkeys (disable + 5 second jump)?

I was expecting space bar presses to click links similar to player controls which operate on space bar, enter, or click. (FWIW collapse / expand all sections button is also only activated by enter but I might expect space bar and right / left arrow keys to work there. Also Auto-advance only works with space bar but I might expect enter and right / left arrow keys to work there too.) When the structure is overflowing and scroll bars appear then space bar does a page down in the structure.

Yes, the player controls activate on both Enter and Space because they are working as buttons. And I was not considering these links are actually presented as buttons to assistive technology tools. Good catch 💯
I will add Space key to activate all the nodes.
As for ArrowRight, it does activate a collapsible node when focused (loads the media into the player on keypress in addition to Enter key). And ArrowLeft collapses a collapsible section. And both of these does nothing when focused on leaf nodes.

Sorry, this part of the comment is not clear to me. Could you please clarify?
collapse / expand all sections button is also only activated by enter but I might expect space bar and right / left arrow keys to work there portion; I understand why we need Space and ArrowRight keys to work here. Are you suggesting we add ArrowLeft key to do the same when focused?

As for auto-advance toggle, Space is expected key to activate it but can have Enter key optionally to activate it according to 'Switch' design pattern which addresses the accessibility of toggle buttons. I'm not sure about using right and left keys to activate the toggle button. I will create a ticket to add this functionality and investigate on using right and left keys.

@Dananji

Dananji commented Mar 31, 2025

Copy link
Copy Markdown
Collaborator Author

New issue for the keyboard accessibility of auto-advance toggle: #796

@cjcolvar

cjcolvar commented Mar 31, 2025

Copy link
Copy Markdown
Member

Thanks for clarifying!

I like the idea of arrow right not doing anything for end nodes and blocking it from advancing the player 5 sec. (Forget about the idea of making all nodes expandable/collapsible. On second thought, I think it would make the UX more confusing and less efficient.)

Looking at the tree view pattern, it seems like right arrow should advance to the first child just like left should go to parent. So for this manifest (https://media.dlib.indiana.edu/media_objects/zg64tm149/manifest.json), I would expect right arrow on Side 1 (when open) to go to Track 1. For your work on nested spans I think right arrow would be able to do more since more hierarchical nodes should be focusable.

For the Collapse/Expand all button, I was thinking it visually looks like a collapsible section node with the icon on the right and thus should maybe behave similarly with right arrow as expand and left arrow as collapse but maybe that is too much and confusing?

@Dananji

Dananji commented Apr 1, 2025

Copy link
Copy Markdown
Collaborator Author

For the Collapse/Expand all button, I was thinking it visually looks like a collapsible section node with the icon on the right and thus should maybe behave similarly with right arrow as expand and left arrow as collapse but maybe that is too much and confusing?

Yes, it makes sense to adapt the same keyboard navigation pattern to this button 👍 Since, it's visualized as the root of the structure I don't think it will be confusing. I'll try it out along with the other changes.

@Dananji
Dananji force-pushed the keyboard-a11y-structure branch from 060d360 to c02de24 Compare April 2, 2025 21:17
@Dananji
Dananji force-pushed the keyboard-a11y-structure branch from c02de24 to 3bbf993 Compare April 3, 2025 15:25

@cjcolvar cjcolvar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the code now and this is looking good! I like the recursive TreeNode component and how it DRYs up the codebase while not being too much more complex. I found a couple things when manually testing. This seems really close to merging!

Comment thread src/components/StructuredNavigation/NavUtils/TreeNode.js Outdated
Comment thread src/components/StructuredNavigation/NavUtils/TreeNode.js Outdated

@cjcolvar cjcolvar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! This will be so much better than what's in MCO right now!

@Dananji
Dananji merged commit 2872071 into main Apr 9, 2025
@Dananji
Dananji deleted the keyboard-a11y-structure branch April 9, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants