Stimulus Has Class
In our current code we are using the hidden CSS class to denote hidden status, and we are hard-coding the class name inside our controller. That’s not really a big deal for a short class name that is unlikely to change, but it’s better practice to not tightly couple the class name to the controller and allow for arbitrary CSS classes. Eventually, we’ll want our controller to have more generic behavior.
Stimulus has a mechanism for this, where we can store the class name as a special data attribute. Essentially, classes are special cases of the values attributes. The name of the data attribute has the form data-<controllerName>-<descriptor>-class, and the value of the attribute is the name of the CSS class being described—typically ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access