Stimulus: Multiple controllers on same element

Created on 9 Apr 2018  路  2Comments  路  Source: hotwired/stimulus

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?

Most helpful comment

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">

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

incompletude picture incompletude  路  3Comments

JanaDeppe picture JanaDeppe  路  4Comments

savroff picture savroff  路  4Comments

paulozoom picture paulozoom  路  4Comments

jenkijo picture jenkijo  路  3Comments