Replies: 2 comments 4 replies
-
One issue here is that I usually recommend reaching for custom elements to help simplify this kind of pattern: https://docs.astro.build/en/guides/client-side-scripts/#web-components-with-custom-elements Agree it would be cool if Astro's editor tooling could know what's in the template! |
Beta Was this translation helpful? Give feedback.
3 replies
-
I would recommend using @bholmesdev 's simple query: https://simple-stack.dev/query It's got everything and more! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Globally scope any ids found on a DOM node in an astro component, similar to css, so it is even easier to reference them in client side
<script>
tags.Important
If per-instance behaviour is desired, inline might be used to opt out of the normal script processing, but that has other footguns due to opting out.
A half joke tweet inspired this.
Background & Motivation
Astro should be the easiest framework to get started right away with web development. Imagine if we didn't even need querySelector / jQuery / or a framework at all to do the example below.
Goals
Example
Example.astro
The ids would be scoped per component instance so the following would work:
Page.astro
And then consider the inline case, so add
And then duplicating works:
Related
Relates to #549 (comment)
We could extend/mix the above with scoped IDs to use some well known symbol Astro compiles away for us, unsure how you would have multiple IDs like I have in my example, tbh I find more value in the global scoped IDs I still manually create and name, rather than an opaque single use symbol/identifier.
Beta Was this translation helpful? Give feedback.
All reactions