-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Scroll to top by default in full-page client-side navigation experiment #62342
base: trunk
Are you sure you want to change the base?
Scroll to top by default in full-page client-side navigation experiment #62342
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Nice!! 😄👏👏
I haven't tested it yet, but one thing:
Is there a need to manage focus here if we're going to scroll the page? |
Like to move it to the first focusable element on the page? |
EDIT: No, it doesn't 😄 I can try to make it work if that's the desired behavior. |
It automatically announces the navigation on the screen reader and shows the animation with the top loading bar, right? But it doesn't change the focus. |
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.
Looks good, Mario! 👍 Just one comment:
If the link includes an anchor, we should scroll to the anchored element. So, e.g. http://my-site.local/hello-world#first-heading
should scroll to the element with the first-heading
id.
You're right we are overriding the scroll to anchor element with this new |
I've just pushed a change, moving the scroll to anchor logic outside of navigate. That should solve the issue mentioned. Apart from that, I am not sure how the screen reader and focus should work. There are a couple of things:
// Set focus at the top of the page.
// Using selectors from https://github.com/KittyGiraudel/focusable-selectors/blob/main/index.js
const not = {
inert: ":not([inert]):not([inert] *)",
negTabIndex: ':not([tabindex^="-"])',
disabled: ":not(:disabled)",
};
const focusableSelectors = [
`a[href]${not.inert}${not.negTabIndex}`,
`area[href]${not.inert}${not.negTabIndex}`,
`input:not([type="hidden"]):not([type="radio"])${not.inert}${not.negTabIndex}${not.disabled}`,
`input[type="radio"]${not.inert}${not.negTabIndex}${not.disabled}`,
`select${not.inert}${not.negTabIndex}${not.disabled}`,
`textarea${not.inert}${not.negTabIndex}${not.disabled}`,
`button${not.inert}${not.negTabIndex}${not.disabled}`,
`details${not.inert} > summary:first-of-type${not.negTabIndex}`,
`iframe${not.inert}${not.negTabIndex}`,
`audio[controls]${not.inert}${not.negTabIndex}`,
`video[controls]${not.inert}${not.negTabIndex}`,
`[contenteditable]${not.inert}${not.negTabIndex}`,
`[tabindex]${not.inert}${not.negTabIndex}`,
];
const firstFocusableElement = document.querySelector(
focusableSelectors.join(", ")
);
firstFocusableElement.focus(); |
@SantosGuillamot Focus does not need to change if the page change is announced. |
@SantosGuillamot Okay, just gave this a test. There is no announcement on page transition so we've got two options.
This way, the user is aware of the page change and can navigate from there. It is hard to say which would be better considering in standard page reloads, users always end up at the start of the site content, generally the skip to main content link. This is a great example of where user testing would be super valuable, study group. CC: @joedolson @afercia Thanks. |
If it's going to visually scroll to a new location, it definitely needs to also change the focus position. The preferred location would be a skip to content link at the top of the page; but if we need to account for the scenario where there is no skip to content link, then it may need to have a fallback, such as setting the focus position at the start of the But any visual change of position must include a change of focus. Setting up a demo environment to conduct some user studies would be very valuable, so we could have people test it in common test scenarios using a variety of different cases: e.g., with skip link and without. |
Single-page app navigation like this 'full-page client-side navigation' must replicate all the native feature of 'classic' navigation with page reload to be fully usable and accessible. Most of this feature are native browser features when a new resource (typically a web page) is loaded in the browser.
|
That makes sense, thank you. For the screen reader announcement, we should reuse the same code that is being used in the region-based client-side navigation (I thought that was already included, but it might not be). If it's also necessary to read the new page title, we can include it in the same announcement and also do the same for the region-based client-side navigation. For the focus, we can try moving it to the SkipToContent link and if that's not available, fall back to the beginning of the |
What?
Automatically scroll to the top of the page when in full-page client-side navigation experiment.
Apart from that, it adds a check to ensure it doesn't overlap with other
data-wp-on--click
directives. This way, they can decide their own behavior as the query loop is doing, for example.Why?
I believe it is the expected behavior.
How?
window.scrollTo( 0, 0 )
after callingactions.navigate
.target
doesn't have thedata-wp-on--click
directive.Testing Instructions