Unifying action attributes
See original GitHub issueHey there, thanks for the new Stimulus 2.0 release!
I really love the new APIs!
After using the new unified target attributes introduced in #202 I asked myself why the same thing wasn’t applied for the action attributes. Was there a specific reason to not do that?
The goal of unifying the target attributes was to align with the new values and classes APIs, so it would make sense to also adopt this syntax to the action attributes, right?
Personally I somehow dislike the new target attributes syntax, because it requires to write more HTML code. Especially if you have a lot of targets in your HTML markup - it seems to clutter up the HTML markup even more, which doesn’t seem to be the goal of Stimulus. You end up with a lot of “new” data attributes on the element which are all named differently compared to one attribute which is always named data-target
but can hold a bunch of targets.
<div data-controller="list sort">
<div data-target="list.item sort.item">...</div>
</div>
Compared to:
<div data-controller="list sort">
<div data-list-target="item" data-sort-target="item">...</div>
</div>
But I guess it just takes some time to get used to it.
Anyway, if we now take a look at the current action attributes it doesn’t behave the same way.
Because the motivation for the target attribute change was to be consistent with the other APIs it would just make sense to also apply this “new” syntax on the action attributes.
Example:
<div data-controller="gallery">
<button data-action="click->gallery#next">…</button>
</div>
becomes:
<div data-controller="gallery">
<button data-gallery-action="click->next">…</button>
</div>
Or using the event shorthand syntax:
<button data-gallery-action="next">…</button>
Either way, I just think it would make sense to have a consistent API for all data attributes😉
I’m happy to discuss or to get to know the thought process behind that change!
Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:21
- Comments:7 (2 by maintainers)
Top GitHub Comments
And please don’t apply this new syntax also on action attributes, that would really destroy the easy convenient HTML markup that stimulus always had. I think data-controller, data-controller, data-action, data-target was always so simple, that’s why I liked stimulus in the first place. And adding data-class, data-values to that would be much better way to go, for me the new syntax is step back.
There is a good reason why the actions are different: All actions are run from left to right and you ca cancel execution at any point, this would not be possible if all controllers had their own action attribute.