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)

Dev Diairies image

User Feedback & The Pivot That Saved The Project

🔥 Check out Episode 3 of Dev Diairies, following a successful Hackathon project turned startup.

Watch full video 🎥

👋 Kindness is contagious

Explore this insightful write-up embraced by the inclusive DEV Community. Tech enthusiasts of all skill levels can contribute insights and expand our shared knowledge.

Spreading a simple "thank you" uplifts creators—let them know your thoughts in the discussion below!

At DEV, collaborative learning fuels growth and forges stronger connections. If this piece resonated with you, a brief note of thanks goes a long way.

Okay