Closed aar0nr closed 6 years ago
We don't have direct support for that, but see https://github.com/stimulusjs/stimulus/issues/35 for a similar discussion and possible solutions.
For example, let's say your building a Popover, but you want to render the popover content in the
<body>
element so it's displayed over all other elements.
In your case, you could try using <body>
as your controller element:
<body data-controller="popover">
<div>
<p>
<button data-action="click->popover#open">Open</button>
</p>
</div>
…
<div data-target="popover.content" hidden>
…
</div>
</body>
Feel free to continue the discussing in https://github.com/stimulusjs/stimulus/issues/35.
How can you render a child element of a controller into a different part of the DOM but delegate the events back to the original controller. This is the portal concept from React.
This is a common pattern with dropdowns, popovers, modals, etc. I'm not sure how to go about handling this scenario in stimulus.
For example, let's say your building a Popover, but you want to render the popover content in the
<body>
element so it's displayed over all other elements.Maybe there is some scope/context trickery that can be done to create some portal-type instance of a controller element, but delegate actions to a different controller? For example:
Have you guys used this pattern for anything on Basecamp? Any tips/ideas?