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.
As a follow-up to hotwired/stimulus#535 and
hotwired/stimulus#546, add support for declaring custom action
modifiers in the same style as
:prevent
,:stop
, and:self
.Take, for example, the toggle event. It's dispatched whenever a
<details>
element toggles either open or closed. If an applicationwere able to declare a custom
open
modifier, it could choose to routetoggle
events denoted with:open
only when the<details open>
.Inversely, they could choose to route
toggle
events denoted with:!open
only when the<details>
does not have[open]
.Similarly, the same kind of customization could apply to custom events.
For example, the turbo:submit-end fires after a
<form>
element submits, but does not distinguish between success or failure. A
:success
modifier could skip events with an unsuccessful HTTP responsecode.
Preview of changes to the
Actions
documentation page:You can register your own action options with the
Application.registerActionOption
method.For example, consider that a
<details>
element will dispatch a toggleevent whenever it's toggled. A custom
:open
action option would helpto route events whenever the element is toggled open:
Similarly, a custom
:!open
action option could route events whenever theelement is toggled closed. Declaring the action descriptor option with a
!
prefix will yield a
value
argument set tofalse
in the callback:In order to prevent the event from being routed to the controller action, the
registerActionOption
callback function must returnfalse
. Otherwise, toroute the event to the controller action, return
true
.The callback accepts a single object argument with the following keys:
"open"
in the example above):open
would yieldtrue
,:!open
would yieldfalse
)