-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add swup-a11y-plugin #34
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||
import { toDash } from '@scripts/utils/string'; | ||||||||||||||||||||||||||
import SwupA11yPlugin from '@swup/a11y-plugin'; | ||||||||||||||||||||||||||
import SwupHeadPlugin from '@swup/head-plugin'; | ||||||||||||||||||||||||||
import SwupPreloadPlugin from '@swup/preload-plugin'; | ||||||||||||||||||||||||||
import SwupScriptsPlugin from '@swup/scripts-plugin'; | ||||||||||||||||||||||||||
|
@@ -55,7 +56,8 @@ export class Transitions { | |||||||||||||||||||||||||
preloadHoveredLinks: true, | ||||||||||||||||||||||||||
preloadInitialPage: !import.meta.env.DEV | ||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||
new SwupScriptsPlugin() | ||||||||||||||||||||||||||
new SwupScriptsPlugin(), | ||||||||||||||||||||||||||
new SwupA11yPlugin() | ||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -105,9 +107,18 @@ export class Transitions { | |||||||||||||||||||||||||
* @see https://swup.js.org/hooks/#visit-start | ||||||||||||||||||||||||||
* @param visit: VisitType | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
onVisitStart() { | ||||||||||||||||||||||||||
onVisitStart(visit: VisitType) { | ||||||||||||||||||||||||||
document.documentElement.classList.add(Transitions.TRANSITION_CLASS); | ||||||||||||||||||||||||||
document.documentElement.classList.remove(Transitions.READY_CLASS); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (visit.a11y) { | ||||||||||||||||||||||||||
visit.a11y.focus = 'h1#page-heading'; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Best not to assume where to move the focus on fragment visits | ||||||||||||||||||||||||||
if (visit.fragmentVisit) { | ||||||||||||||||||||||||||
visit.a11y.focus = false; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+114
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would discourage this for most standard pages. The On pages that use modals/drawers, that container or its main heading should receive focus. If you insist on keeping this, the logic should be collapsed into a single statement:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pages using modals/drawers are typically in a The issue I see with other types of fragment visits (probably a single section inside the main of the page) resetting the focus to the body is it will require the user to travel again across the page to reach the updated content which could be irritating and potentially disorienting? But at the same time, it's how it would behave without an SPA system... so I'm not entirely sold on that Also, I posted a comment asking for your advice regarding this bit of code but I didn't notice Github left it as "pending" which prevented you from seeing it.. my bad! It brings some explanations to my thought process there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stick to Web standards and its default, established, behaviours. If a project's stakeholders can afford to hire accessibility consultants and dedicate time to testing with real users, then the behaviour can be adjusted to accommodate their expectations. |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,8 @@ type VisitType = { | |
to: { | ||
html: string; | ||
}; | ||
a11y?: { | ||
announce: string; | ||
focus: string | false; | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have @mcaskill input on this.
I noticed by testing VoiceOver that a page change would either:
#swup
container)Considering those observations, specifying the focus target on the page heading seems pertinent! But it seems to prevent Swup's aria-live announcements to happen as a side effect... Not sure if that's a real issue though as the plugin announces
Navigated to {title}
by default (title value being decided as such).We're basically only losing the
Navigated to
bit, but that bit increases clarity about what's happening.Could you please try the navigation behavior with/without this line and give your recommendation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, Swup is the one at fault for the recent issue I noticed across some projects where the page does not scroll back to the top after clicking a hyperlink in the footer.
Swup created a problem and instead of fixing it introduces a non-standard solution.
If its announcing
Navigated to {title}
that means itsaria-live
element is working as intended. It's extracting the text node from the first<h1>
which happens to be the target of yourvisit.a11y.focus
.Since the
<h1>
can't be guaranteed to have a relevant title, maybe the plugin'sheadingSelector
could target<title>
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. What I'm saying is that this doesn't happen anymore if I specify a focus target with
visit.a11y.focus = 'h1#page-heading';
. Seems like the element being focused steals the VoiceOver attention to the detriment of thearia-live
element.Can you send me an example of a project where you noticed this on Slack? It's not necessarily related
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In regards to
visit.a11y.focus
, that makes sense that it's stealing focus. Not necessarily the intended behavior. I noticed that Swup's documentation site still uses v4 whose behaviour is to focus the firsth1
.