Skip to content

ENH Add aria attrs to site tree#3120

Open
emteknetnz wants to merge 1 commit intosilverstripe:6from
creative-commoners:pulls/6/tree-aria
Open

ENH Add aria attrs to site tree#3120
emteknetnz wants to merge 1 commit intosilverstripe:6from
creative-commoners:pulls/6/tree-aria

Conversation

@emteknetnz
Copy link
Copy Markdown
Member

@emteknetnz emteknetnz force-pushed the pulls/6/tree-aria branch 2 times, most recently from 6441414 to 3a39359 Compare October 13, 2025 01:45
@emteknetnz emteknetnz marked this pull request as ready for review October 13, 2025 01:45
Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

There are various recommendations in the W3C example which probably apply to our usage, since that example is for a tree used as navigation which is what we're doing here.

I recommend we follow that example, including add a nav parent to the tree list (instead of the current div), and additional recommendations such as using the aria-current attribute etc.
Note that not everything in the live example has a corresponding textual recommendation - but IMO we should treat the example's aria attributes as best practice anyway. I've marked some (but not all) of the differences between their example and this implementation in separate PR comments.

We can however ignore some of the recommendations from that example that are for regular websites, such as the use of the banner landmark.

I will note that Orca (the screen reader I'm using for testing) works really well both in terms of correctly announcing tree items and the tree itself and in terms of respecting correct key bindings with the W3C example than with our site tree. In our one orca didn't seem to recognise it was in a tree at all, and wouldn't respect the left/right arrow keybindings.

Comment on lines +10 to +11
><ins class="jstree-icon font-icon-right-dir"
role="button"
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.

We should just use a semantic button element instead of an inserted text element which is just completely symantically incorrect.

While screen readers should use the role attribute, some won't (unfortunately orca which I'm using to test is one that won't) so we should use semantically correct HTML elements wherever possible.

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.

That said - in the W3C example the arrows aren't actually separately tabbable - instead the treeitem intercepts key presses for left/right arrows for expanding/collapsing, and the arrow is just a span with a click handler for mouse interaction.

This is more consistent with the keyboard interaction recommendations W3C make (it makes no mention of tab or enter for expanding/collapsing child nodes). Perhaps we should follow their example here as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not going to change HTML tags (will affect styling) or tab order (will affect behat tests) in this PR - I've created a follow up issue for this

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.

It feels like you might have not seen the second comment there, about making these not tabbable and not using the button role? If we do that, it doesn't really matter what the HTML tag is because assistive technologies will ignore them anyway - they'll only be for mouse interaction for sighted users.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As previously mentioned, changing either the html tags or the tab order will affect styling / css and behat and I do not want to that in this PR as this one is focused on aria attrs. I have created a follow up issue to implement those.

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.

This is nearly the only problem now with what the screen reader is saying. Whenever I tab to one of these button-not-buttons, it leaves the context of the tree. The screen reader changes to "browse mode". When I tab back off it, it enters the context of the tree again, and I get told all the tree information (level 2, etc).

What interactive elements live where very much impacts the screen reader experience - it's hard to say "yes this is done the screen reader experience is good now" when this interactive element is interfering with that experience. These two things inform one another.

I guess I have to call it done and then when the follow up issue is implemented, I have to check it again and see how it impacts the screen reader experience? And then if more changes are needed to the aria attributes, we'll open another separate card to address it separately again?

@emteknetnz emteknetnz force-pushed the pulls/6/tree-aria branch 2 times, most recently from e971648 to 75a3ff2 Compare October 14, 2025 05:37
Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

The experience with a screen reader still isn't the same or as good as the W3C example. Are you using a screen reader to test this?
One clear example is when I use left/right arrow keys to expand/collapse a node, with the W3C example the screen reader announces "collapsed" or "expanded" as appropriate. With this PR I get no feedback at all.

I again recommend we follow the W3C example as closely as we can.

Comment on lines +10 to +11
><ins class="jstree-icon font-icon-right-dir"
role="button"
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.

It feels like you might have not seen the second comment there, about making these not tabbable and not using the button role? If we do that, it doesn't really matter what the HTML tag is because assistive technologies will ignore them anyway - they'll only be for mouse interaction for sighted users.

@emteknetnz
Copy link
Copy Markdown
Member Author

emteknetnz commented Oct 15, 2025

Have moved all the aria stuff off the <li> on to the <a>, seems to be closer to the w3c example now

Copy link
Copy Markdown
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

There's a merge conflict.

The only other thing remaining that bothers me (other than the <ins> stuff) is the level starts at level 2? Feels like the root level pages should all be level 1.

Comment on lines +10 to +11
><ins class="jstree-icon font-icon-right-dir"
role="button"
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.

This is nearly the only problem now with what the screen reader is saying. Whenever I tab to one of these button-not-buttons, it leaves the context of the tree. The screen reader changes to "browse mode". When I tab back off it, it enters the context of the tree again, and I get told all the tree information (level 2, etc).

What interactive elements live where very much impacts the screen reader experience - it's hard to say "yes this is done the screen reader experience is good now" when this interactive element is interfering with that experience. These two things inform one another.

I guess I have to call it done and then when the follow up issue is implemented, I have to check it again and see how it impacts the screen reader experience? And then if more changes are needed to the aria attributes, we'll open another separate card to address it separately again?

Comment on lines +186 to +192
// Add role="tree" to the root level <ul> for accessibility
// This needs to be done with JS as jstree will override any attributes set server-side
$('.cms-tree > ul').entwine({
onmatch: function() {
this.attr('role', 'tree');
}
});
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.

We should probably use one of the jstree events, such as loaded.jstree (similar to other events already in silverstripe/silverstripe-admin#2016)

@emteknetnz emteknetnz force-pushed the pulls/6/tree-aria branch 2 times, most recently from 8f458be to ebfc0e6 Compare March 27, 2026 01:24
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