DEV Community

Scott Barrow
Scott Barrow

Posted on • Edited on

1

self-referential data-reflex-root

It can sometimes be tricky to re-render an element, partial or view component in a selector morph from a reflex, especially if it needs new.

An alternative approach to selector morphs is wrapping your element(s) in a div with data-reflex-root. The value of the data attr will be used as the selector(s) for the morph.
A neat trick is that you can do this on itself

<div id="unique-morph-target" data-controller='resource-toggle-component' data-reflex-root='#unique-morph-target'>
Enter fullscreen mode Exit fullscreen mode

N.b. only the children of this element will be morphed, and not the element itself!
One major difference is that this approach still hits the controllers original action, which may or may not be desirable.
There’s nothing special needed in the reflex
ref: https://docs.stimulusreflex.com/morph-modes#scoping-page-morphs

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay