I tried searching but didn’t find an answer. Is it possible to have a space delimited list of multiple css class names for the stimulus js css class api? I’m only able to get it working with one css class name.
e.g. data-sample-foo-class="one-item-css-class"
But I want to use two or more css classes. something like data-sample-foo-class="class-one class-two"
Is there a way to do this elegantly? I’m currently assigning each class individually and it’s cumbersome.
Stimulus does not restrict you from assigning multiple classes to a class variable and element.classList.add can take multiple classes as separate parameters.
element.classList.add('one', 'two', 'three')
Using the spread operator you can covert an array into multiple parameters, something like:
<form data-controller="search"
data-search-loading-class="one two three">