Fix: Dispatch turbo:click
when driving a Frame
#729
Merged
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:click
events in the same way that theydid before hotwired/turbo#412.
This commit re-instates those events as part of the
FrameController
and
FrameRedirector
implementations for thewillFollowLinkToLocation
methods they define as part of the
LinkClickObserverDelegate
interface.
To be consistent with the existing
turbo:click
dispatch 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: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
andturbo:before-visit
). Next, implementcancelNextVisit
in terms ofcancelNextEvent
.Finally, use the
cancelNextEvent
helper in the Frame test coverage toensure that canceling a
turbo:click
prevents navigating the Frame andfalls back to built-in browser behavior.