Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to use comments as anchor for components? #4544

Closed
shirotech opened this issue Mar 11, 2020 · 2 comments
Closed

Any way to use comments as anchor for components? #4544

shirotech opened this issue Mar 11, 2020 · 2 comments

Comments

@shirotech
Copy link

i.e. currently I have something like this in my component.

<script>
  let ref;

  onMount(() => {
    const child = ref.nextElementSibling;
  });
</script>

<span bind:this={ref} style="display:none"></span><slot/>
<div>some content</div>

Was wondering if there is any easy way to access the dom element of a slot? If we need some kind of anchors, is it possible to use a comment or even a text node? Many thanks.

@Conduitry
Copy link
Member

For default slots (and hopefully eventually for named slots) there isn't necessarily a single top-level DOM element associated with the slot. There's an open issue #2106 for providing an official way of seeing whether a slot has content, but I don't think there's been much discussion about what the exposed value would be, besides truthy vs falsy.

If you're asking for something like bind:this on comment nodes, that seems niche enough that it would be very low priority if it were accepted as a proposed feature.

@AlbertMarashi
Copy link

+1 for this, getting a bind:this on comment nodes or possibly even text nodes would be really useful for page builders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants