-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(theme-classic): fix SkipToContent without JS , refactor, make it public theming API #8204
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Thanks, that looks like a good solution
Note I don't know exactly why we need this JS code. I didn't add this code but it looks most of it was added here: #4162 const targetElement: HTMLElement | null =
document.querySelector('main:first-of-type') ??
document.querySelector(`.${ThemeClassNames.wrapper.main}`); The Maybe we could check if the id target exists in the DOM, and only execute the sensible JS fallback + preventDefaults in case it doesn't? What if the user implements a custom page, not applying our layout component Regarding this code: useLocationChange(({location}) => {
if (containerRef.current && !location.hash && action === 'PUSH') {
programmaticFocus(containerRef.current);
}
}); I don't know for sure what's the best a11y behavior here, but to me the goal is to "reset" the focus so that the first tabbed items becomes the "skipToContent" link after a SPA navigation. If you don't do this, then when navigating from the docs sidebar, the clicked doc sidebar item would stay focused And browsing the main content on the new page may become more complicated? @lex111 @locriacyber @Mythra @JoshuaKGoldberg @BenDMyers if you have any opinion on how skip to content is supposed to be integrated into a SPA vs MPA, now is the best time :) |
Hi, happy to be pinged in a11y stuff again. First off I can't overstate how much I love the change of just using a default anchor link. It's something I wanted originally (and mentioned in one of the first prs/issues), but wasn't chosen at the time because there were some worries about themes potentially not providing the right ID. So getting us closer to that is awesome. As for "how skip to content link should work", I'll point to the WCAG guidelines: https://www.w3.org/TR/WCAG20-TECHS/G1.html these are what most people have to comply too, and does a great job of covering universally disabilities that may need to use this behavior. The first tabbed item should always be the skip to content link when on what is a new "page". So if you're in an SPA app where moving to a new page with the same navigation elements around that a user should have to tab through, then yes focus should first go to skip to content link. If it's within a page fragment where the focus is already where it needs to be past all the navigation? No need to reset all the way back up. At least that's what I'd expect as someone who uses a screen reader daily (and my reading of the spec!), but there may be others who have separate opinions. |
Thanks @Mythra , I understand better
For a SPA, the concept of a "new page" is kind of ambiguous. We can have nested layouts where navigating only change a nested container of the main layout, but not the "shell" around it. Is this considered as a "new page" when this red square change or not?
My understanding is that we are in this case here, so it makes sense to use JS to give focus back to the skip to content link when navigating any sidebar item. The good news is that using JS doesn't seem to be a problem:
Not sure to understand in what case this happens. Maybe a system where you can tab through items on a page, and tabs are persisted in the url/querystring? Technically it is a navigation (push or replace) but we probably don't want to reset focus in such case? |
@Mythra I am also not sure what is meant here. Is for example tabs navigation a good example for this? @slorber I addressed your review comments, please let me know if there is anything else I can do to get this merged. Thanks! |
# Conflicts: # packages/docusaurus-theme-common/src/index.ts
Thanks @mturoci, I did some additional refactors needed for sharing this behavior across themes, and also added some useful comments so that we still understand how it works later 😅 Otherwise the solution looks good enough 👍 |
…public theming API (#8204) Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com> # Conflicts: # packages/docusaurus-theme-common/src/index.ts
Pre-flight checklist
Motivation
Allow skipping to content despite disallowed JS.
Test Plan
Manual.
Test links
Deploy preview: https://deploy-preview-8204--docusaurus-2.netlify.app/
Related issues/PRs
Closes #6411