Fix: Dispatch turbo:click when driving a Frame#729
Merged
dhh merged 1 commit intohotwired:mainfrom Sep 22, 2022
Merged
Conversation
719306c to
be9091a
Compare
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
be9091a to
950f247
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:clickevents in the same way that theydid before hotwired/turbo#412.
This commit re-instates those events as part of the
FrameControllerand
FrameRedirectorimplementations for thewillFollowLinkToLocationmethods they define as part of the
LinkClickObserverDelegateinterface.
To be consistent with the existing
turbo:clickdispatch behavior, andto guard against introducing similar regressions in the future, this
commit also adds test coverage for falling back to page-wide navigations
when
turbo:clickevents are canceled.In support of those changes, first, introduce the
cancelNextEventhelper to accept the name of a Turbo event that is cancellable (in this
case,
turbo:clickandturbo:before-visit). Next, implementcancelNextVisitin terms ofcancelNextEvent.Finally, use the
cancelNextEventhelper in the Frame test coverage toensure that canceling a
turbo:clickprevents navigating the Frame andfalls back to built-in browser behavior.