-
Notifications
You must be signed in to change notification settings - Fork 26
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
Event property to access the element who triggered a navigation #225
Comments
That seems like a pretty reasonable addition. This information is similar to Any thumbs-up on the issue from community members would be appreciated, to weigh this versus other additions. |
Other libraries in the same space that might be interested by this new API and/or this issue: htmx (cc @benpate) and Unpoly (cc @triskweline). |
What is the current status of this API? From this page, it seems like a proposal that hasn't yet been implemented by W3C or major browsers. It certainly looks interesting, and I'll keep an eye on it as it develops! Also -- thanks for the mention! @1cg is the rockstar behind htmx. I'm just a groupie with a pair of drumsticks :) |
We are preparing to ship this in Chromium, after having run an origin trial for a while. You can find out some details on other browsers' engagement on that link. The W3C does not implement APIs so I don't know what you mean by that. |
Thanks for the mention @rik. Confirming that this would be relevant for Unpoly, as we're trying to update a minimal fragment around the triggering element (link, submit button) that causes a navigation. In Unpoly the triggering element is called |
For a use case of where having the element triggering the navigation event would be needed checkout the duplicate issue I previously created: #238 . tl;dr codefunction visit(params) {
// ...
navigation.addEventListener('navigate', (e) => {
const element = e.targetElement; // <- Element or null
if (!element || !element.hasAttribute('data-visit')) {
return;
}
e.transitionWhile(
fetch({
url: element.getAttribute('data-visit-url') || determineUrlToUseFromElement(element),
method: element.getAttribute('data-visit-method') || determineMethodToUseFromElement(element),
// ...
})
.then(response => response.text())
.then(html => swapDom(html))
);
});
} |
A few design questions that came up:
|
|
It is often-but-not-always user initiataed, fwiw. At least the way I prototyped it, a form submission will populate the triggering element, even if it was submitted via I agree that
Just to clarify: This will be available for cross-document navigations, but not cross-window initiation.
The submitting |
I think it should be the <form>
<button type="submit">Intercepts the submission</button>
<button type="submit" data-turbo="false">Let the browser navigate as usual</button>
</form> |
Oh and I suppose Just some options: I don't have strong opinions I think most of these would be clear. Ack with cross-window initiation, that was my understanding as well. +1 to |
Yes. Same if you call |
Trying to settle on the final naming:
Thoughts welcome. This is a pretty simple addition so let's nail down the name soon. |
Some thoughts:
|
My instinct is no. Between this and
The only extra thing we could consider giving you is the ability to know exactly which API method was used, e.g.
Great point. I think Nate implemented a same-document restriction, but forgot to mention that in #264. That seems like the right conservative starting point. Although I guess it kind of belies my above breakdown; if a cross-document
Yes. We haven't written the spec yet, but I think the way to do things will be to convert sourceDocument into sourceNode, extract out sourceDocument (always non-null) and sourceElement (sometimes non-null) from it early in the navigate algorithm, and pass sourceDocument on to the rest of the algorithm while passing sourceElement on to the specific parts concerned with firing the |
Fine with Re: booleans, I suppose you would have to check |
I also think |
I'm not seeing this in the merged version within the HTML spec. Are there any blockers to do so? |
Nope, @natechapin is working on it :) |
I can see that this has been "Implemented behind the NavigateEventSourceElement flag" in Chromium How do we enable that flag to try it out? Under what circumstances would it be un-flagged? |
To give it a try, launch Chrome with this extra argument: |
Is there any movement on when this will be unflagged in Blink? Also, do we know whether It's immensely useful to be able to toggle an It's hard to understand the status on w3ctag/design-reviews#867 – for clarity: was this closed because TAG don't need to review and therefore it's just automatically accepted as an addition? |
I apologize for the lack of progress in shipping sourceElement. It fell through the cracks in a bit of a team transition. I'll try to bump shipping it higher on the priority queue. |
This would be very helpful for View Transitions, so that one can capture the correct element – by adding a |
I think this new API could be very interesting for a library like Hotwire Turbo. The Turbo Frame concept would need to know if the navigation was triggered by an element or not and if that element was configured to do a Turbo navigation or not. As far as I can tell, this information is not available at the moment.
(cc @seanpdoyle from the Turbo community)
The text was updated successfully, but these errors were encountered: