State of component visibility with events #3089
Replies: 2 comments 4 replies
-
If something like that gets implemented, it could probably be an event so you can have |
Beta Was this translation helpful? Give feedback.
-
I would kill for an x-shown or on:shown event. If the Alpine team is reading this, it's a big deal. I'm trying to display Google Graphs on tab panels and the graphs don't render reliably unless the tab panel is visible (because the sizing isn't clear if the panel is hidden). Since I have four tab panels, and all the graphs are rendered when the page is loaded, three of the panels are hidden when the graphs are rendered. |
Beta Was this translation helpful? Give feedback.
-
Hi, Alpine.js has both
x-if
andx-show
to control both DOM presence and DOM visibility while using "inline" declarative style. Visibility is very important and useful state, that is whyx-show
exists.When using components, Alpine.js has good support for DOM presence because it offers
x-init
to bind handlers of component creation. However component visibility is not supported very well. It does not offer events or hooks to bind handlers for component visibility.I would like something like this:
This would be useful to manage component lifecycle in a way that components are preloaded on
init
and later show instantly. The trick is to load JS libraries or complicated components oninit
and then later show them onshown
. However sometimes there are many nested components and parent component holds the visibility state of child. It would be useful to just get listen to visibility change from Alpine.js and not access parent state to get visibility state. Components can be placed in different files so it is good for readability not to rely on parent state. For example:Also this would help also:
Or:
And maybe
x-init
could be modified too:Beta Was this translation helpful? Give feedback.
All reactions