Skip to content

Docs: Nav better a11y#41483

Merged
julien-deramond merged 2 commits intomainfrom
main-lmp-nav-for-sidebar
May 23, 2025
Merged

Docs: Nav better a11y#41483
julien-deramond merged 2 commits intomainfrom
main-lmp-nav-for-sidebar

Conversation

@louismaximepiton
Copy link
Member

@louismaximepiton louismaximepiton commented May 22, 2025

Description

Add a label to the <nav>.

Motivation & Context

Some a11y improvements according to https://www.w3.org/WAI/tutorials/page-structure/labels/.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Live previews

Related issues

NA

@louismaximepiton louismaximepiton changed the title Better a11y Docs: Nav better a11y May 22, 2025
@github-project-automation github-project-automation bot moved this to To do in v5.3.7 May 22, 2025
@julien-deramond julien-deramond moved this from To do to Needs review in v5.3.7 May 22, 2025
<hr class="d-none d-md-block my-2 ms-3" />
<div class="collapse bd-toc-collapse" id="tocContents">
<nav id="TableOfContents">
<nav id="TableOfContents" aria-labelledby="docs-tocs">
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure, but just from reading the code, it looks like:

  • On mobile (d-md-none), we display a button with the text 'On this page'.
  • On desktop (d-none d-md-block), we display a <strong> element with the same text.

The aria-labelledby attribute points to the <strong> element, which is hidden on mobile.

Doesn't that mean screen reader users on mobile won't get the correct label, since the referenced element isn't visible?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have any issue on my side using NVDA on Firefox/Chrome. If you prefer I can add an aria-label

Copy link
Member

Choose a reason for hiding this comment

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

It looks a bit odd in the code, but hey—if it works, it works! 😄
@patrickhlauke, curious to hear your thoughts on this approach?

Copy link
Member

Choose a reason for hiding this comment

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

a priori, that looks kosher to me

Copy link
Member

Choose a reason for hiding this comment

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

just tested just with Chrome/VO/iOS and yes, it works fine there too (I believe this is that special behaviour where aria-labelledby/aria-describedby do still have access to element content, even when it's display:none'd

@julien-deramond julien-deramond moved this from Needs review to Review in progress in v5.3.7 May 22, 2025
@julien-deramond julien-deramond moved this from Review in progress to Ready to merge in v5.3.7 May 23, 2025
@julien-deramond julien-deramond merged commit a749136 into main May 23, 2025
14 checks passed
@julien-deramond julien-deramond deleted the main-lmp-nav-for-sidebar branch May 23, 2025 09:06
@github-project-automation github-project-automation bot moved this from Ready to merge to Done in v5.3.7 May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants