mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Fix ARIA labels for all anchors with href="#"
; adds aria-pressed
information for toggles (#1262)
This follows up from #1259 and closes #1261. Basically, this PR accomplishes the two items discussed in the issue: 1. for all anchors that are *actually* buttons (i.e., have `href="#"`), I've replaced them with a semantic `<button>` - under the hood, I've made a `.btn-reset` class pulling out the reset from #1259, so there's no visual change 2. for anchors that are ["toggle buttons"](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role#toggle_buttons) (the mobile menu nav, sidebar children/grandchildren toggles), I've added an `aria-pressed` property that is updated as the button is clicked I've also slightly modified some of the `aria-label`s to make them more consistent. Observe that we *shouldn't* update these as the button is clicked; screen readers use the `aria-pressed` property to add an annotation to each button. To test this, - the sidebar children and grandchildren can be done on the deploy preview: - open an arbitrary page; observe that the sidebar children/grandchildren dropdown ticks now have a proper `aria-label` and `aria-pressed`, as well as otherwise work as intended - toggle one of the buttons; observe the `aria-pressed` role changing as this is done - open a grandchild page; observe that the `aria-pressed` has a correct default wrt whether or not the page is active - the mobile menu can be done on the deploy preview; on a smaller viewport, observe the correct `aria-pressed` - two features require local changes to test: - the `site.search.button` needs to be enabled in the `_config.yml`. To test this, locally clone the repo, change the flag, and observe that the button still works as intended + has no visual regressions. - the collections feature is a bit more complicated. To test this, locally clone the repo, add an arbitrary collection and changes to `_config.yml`, and observe the same behaviour for the sidebar children/grandchildren above
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
Results in: HTML for the navigation panel.
|
||||
Includes:
|
||||
sorted_pages.html
|
||||
Overwrites:
|
||||
Overwrites:
|
||||
nav_pages, first_level_pages, second_level_pages, third_level_pages,
|
||||
node, children_list, child, grand_children_list, grand_child.
|
||||
{%- endcomment -%}
|
||||
@@ -26,29 +26,29 @@
|
||||
{%- comment -%}
|
||||
The order of sibling pages in `sorted_pages` determines the order of display of
|
||||
links to them in lists of navigation links.
|
||||
|
||||
|
||||
Note that Liquid evaluates conditions from right to left (and it does not allow
|
||||
the use of parentheses). Some conditions are not so easy to express clearly...
|
||||
|
||||
|
||||
For example, consider the following condition:
|
||||
|
||||
C: page.collection = = include.key and
|
||||
page.url = = node.url or
|
||||
page.grand_parent = = node.title or
|
||||
page.parent = = node.title and
|
||||
|
||||
C: page.collection = = include.key and
|
||||
page.url = = node.url or
|
||||
page.grand_parent = = node.title or
|
||||
page.parent = = node.title and
|
||||
page.grand_parent = = nil
|
||||
|
||||
|
||||
Here, `node` is a first-level page. The last part of the condition
|
||||
-- namely: `page.parent = = node.title and page.grand_parent = = nil` --
|
||||
is evaluated first; it holds if and only if `page` is a child of `node`.
|
||||
|
||||
The condition `page.grand_parent = = node.title or ...` holds when
|
||||
|
||||
The condition `page.grand_parent = = node.title or ...` holds when
|
||||
`page` is a grandchild of node, OR `...` holds.
|
||||
|
||||
The condition `page.url = = node.url or ...` holds when
|
||||
|
||||
The condition `page.url = = node.url or ...` holds when
|
||||
`page` is `node`, OR `...` holds.
|
||||
|
||||
The condition C: `page.collection = = include.key and ...` holds when we are
|
||||
|
||||
The condition C: `page.collection = = include.key and ...` holds when we are
|
||||
generating the nav links for a collection that includes `page`, AND `...` holds.
|
||||
{%- endcomment -%}
|
||||
|
||||
@@ -57,9 +57,9 @@
|
||||
{%- unless node.nav_exclude -%}
|
||||
<li class="nav-list-item{% if page.collection == include.key and page.url == node.url or page.grand_parent == node.title or page.parent == node.title and page.grand_parent == nil %} active{% endif %}">
|
||||
{%- if node.has_children -%}
|
||||
<a href="#" class="nav-list-expander" aria-label="toggle links in {{ node.title }} category">
|
||||
<svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg>
|
||||
</a>
|
||||
<button class="nav-list-expander btn-reset" aria-label="toggle items in {{ node.title }} category" aria-pressed="{% if page.collection == include.key and page.url == node.url or page.grand_parent == node.title or page.parent == node.title and page.grand_parent == nil %}true{% else %}false{% endif %}">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
|
||||
</button>
|
||||
{%- endif -%}
|
||||
<a href="{{ node.url | relative_url }}" class="nav-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
|
||||
{%- if node.has_children -%}
|
||||
@@ -73,9 +73,9 @@
|
||||
{%- unless child.nav_exclude -%}
|
||||
<li class="nav-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}">
|
||||
{%- if child.has_children -%}
|
||||
<a href="#" class="nav-list-expander" aria-label="toggle links in {{ child.title }} category">
|
||||
<svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg>
|
||||
</a>
|
||||
<button class="nav-list-expander btn-reset" aria-label="toggle items in {{ child.title }} category" aria-pressed="{% if page.url == child.url or page.parent == child.title %}true{% else %}false{% endif %}">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg>
|
||||
</button>
|
||||
{%- endif -%}
|
||||
<a href="{{ child.url | relative_url }}" class="nav-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a>
|
||||
{%- if child.has_children -%}
|
||||
|
Reference in New Issue
Block a user