-
Notifications
You must be signed in to change notification settings - Fork 4.5k
iAPI Router: Prioritize custom click event handlers when full-page navigation is enabled #70566
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
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.
LGTM 🙂 Seems to work as described.
While testing it, I noticed that it doesn't scroll to the top if there are no links in the query loop (which is the case in the default layout). I assume that's a different discussion, but do you think that should be addressed in other pull request? Or is it expected?
Yes, @SantosGuillamot, we would need to address that issue later on. I think the gutenberg/packages/interactivity-router/src/index.ts Lines 392 to 396 in 3fd77b3
Also, I'd love to hear from @luisherranz on this matter. 🙂 |
What do you mean by "if there are no links in the query loop"?
In my opinion, we should scroll to the top and move the focus to the first focusable element on the page only on regular links of full-page client-side navigation. The scroll to top and focus control should happen here: gutenberg/packages/interactivity-router/src/full-page.ts Lines 23 to 31 in 1d0c43d
With region-based client-side navigation, things are different. I think whoever calls By default, I don't think scroll should happen in region-based client-side navigation because it's intended to replace content blocks within a page rather than the entire page itself. Typically, users will prefer to keep their scroll position and context during navigation. Focus in region-based client-side navigation is also tricky because it depends on the use case. Usually, you'll want to set focus somewhere within the region that's been updated. So it should also be the responsibility of whoever is calling |
From my testing and what I understand from this code, it only focuses and scrolls to the top when there is a link. For example, if I have a Post Title and a Post Image inside the Post Template, it only scrolls to the top when the Post Title has the "Make title a link" setting enabled. |
Ah, ok, I get it now. Thanks. It's not actually scrolling to the top. It's scrolling to that link because of the focus. Maybe we should change it to any focusable element, not just links. Although that code already received an accessibility review. |
What?
Gives priority to custom click event handlers, typically defined with
data-wp-on--click
directives, over the global click event handler that controls all site links added by the@wordpress/interactivity-router/full-page
module.This fixes the click logic of the Query Pagination blocks.
Why?
Specific behavior defined in blocks should take precedence over the more general full-page behavior. This block-specific behavior, added to a link, would typically handle navigation.
How?
The
useCapture
value oftrue
is removed. That would make any event handler callingevent.preventDefault()
to effectively prevent the event from being captured by the full-page event listener.Testing Instructions
trunk