I was planning on using stimulus controllers for "higher order components." To do this, I wanted to just put multiple data-controllers on the <body> tag. However, it seems Stimulus will only boot one controller per element. As a workaround, I'm just creating empty <div>s. But I'm curious, what's the reasoning behind one controller per element? Is Stimulus simply not the right use case for these types of functionality?
You can connect multiple controllers to an element by placing a space-separated list of controller names in the data-controller attribute, in the same way you would specify multiple CSS class names:
<body data-controller="search list-selection">
Thank you, I was JUST about to respond with that.
Most helpful comment
You can connect multiple controllers to an element by placing a space-separated list of controller names in the
data-controllerattribute, in the same way you would specify multiple CSS class names: