Skip to content

Fix: Dispatch turbo:click when driving a Frame#729

Merged
dhh merged 1 commit intohotwired:mainfrom
seanpdoyle:frame-turbo-click-event
Sep 22, 2022
Merged

Fix: Dispatch turbo:click when driving a Frame#729
dhh merged 1 commit intohotwired:mainfrom
seanpdoyle:frame-turbo-click-event

Conversation

@seanpdoyle
Copy link
Copy Markdown
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.

@seanpdoyle seanpdoyle force-pushed the frame-turbo-click-event branch 4 times, most recently from 719306c to be9091a Compare September 21, 2022 14:07
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
@seanpdoyle seanpdoyle force-pushed the frame-turbo-click-event branch from be9091a to 950f247 Compare September 21, 2022 14:17
@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