Skip to content
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: Dispatch turbo:click when driving a Frame #729

Merged
merged 1 commit into from Sep 22, 2022

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Sep 21, 2022

Closes #726

Prior to this commit, clicking on <a> elements nested within
<turbo-frame> elements, or <a> elements that drive <turbo-frame>
elements did not dispatch turbo:click events in the same way that they
did before hotwired/turbo#412.

This commit re-instates those events as part of the FrameController
and FrameRedirector implementations for the willFollowLinkToLocation
methods they define as part of the LinkClickObserverDelegate
interface.

To be consistent with the existing turbo:click dispatch behavior, and
to guard against introducing similar regressions in the future, this
commit also adds test coverage for falling back to page-wide navigations
when turbo:click events are canceled.

In support of those changes, first, introduce the cancelNextEvent
helper to accept the name of a Turbo event that is cancellable (in this
case, turbo:click and turbo:before-visit). Next, implement
cancelNextVisit in terms of cancelNextEvent.

Finally, use the cancelNextEvent helper in the Frame test coverage to
ensure that canceling a turbo:click prevents navigating the Frame and
falls back to built-in browser behavior.

Closes hotwired#726

Prior to this commit, clicking on `<a>` elements nested within
`<turbo-frame>` elements, or `<a>` elements that drive `<turbo-frame>`
elements did not dispatch `turbo:click` events in the same way that they
did before [hotwired#412][].

This commit re-instates those events as part of the `FrameController`
and `FrameRedirector` implementations for the `willFollowLinkToLocation`
methods they define as part of the `LinkClickObserverDelegate`
interface.

To be consistent with the existing `turbo:click` dispatch behavior, and
to guard against introducing similar regressions in the future, this
commit also adds test coverage for falling back to page-wide navigations
when `turbo:click` events are canceled.

In support of those changes, first, introduce the `cancelNextEvent`
helper to accept the name of a Turbo event that is cancellable (in this
case, `turbo:click` and `turbo:before-visit`). Next, implement
`cancelNextVisit` in terms of `cancelNextEvent`.

Finally, use the `cancelNextEvent` helper in the Frame test coverage to
ensure that canceling a `turbo:click` prevents navigating the Frame and
falls back to built-in browser behavior.

[hotwired#412]: hotwired#412
@dhh dhh merged commit 329e837 into hotwired:main Sep 22, 2022
@seanpdoyle seanpdoyle deleted the frame-turbo-click-event branch September 28, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

turbo:click is not fired when navigating using frames
2 participants