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

Allow access to Slot elements from the component #2092

Closed
AllanOricil opened this issue Nov 13, 2020 · 6 comments
Closed

Allow access to Slot elements from the component #2092

AllanOricil opened this issue Nov 13, 2020 · 6 comments

Comments

@AllanOricil
Copy link
Contributor

AllanOricil commented Nov 13, 2020

Is your feature request related to a problem? Please describe.
No. It is a feature request.

I want to access the list of slots from within the parent

<template>
    <div>
        <slot></slot>
    </div>
</template>
import { api, LightningElement } from 'lwc';

export default class Parent extends LightningElement {

    connectedCallback(){
         //parent has access to slots
         this.slots.forEach((slot) => {
            console.log(slot);
        }

    }

}

Describe the solution you'd like
this.slots must be accessible from parent

Describe alternatives you've considered
use lwc:dom

@AllanOricil AllanOricil changed the title Allow Slot elements Access from child Allow access to Slot elements dynamically Nov 16, 2020
@AllanOricil AllanOricil changed the title Allow access to Slot elements dynamically Allow access to Slot elements from the component Nov 16, 2020
@Bartheleway
Copy link

Hi @AllanOricil, I believe your issue is somehow similar to mine #2218 in a more complex example. It doesn't seems possible currently to have slot in loop.

@nolanlawson
Copy link
Collaborator

This sounds like a request for what we're calling "scoped slots": salesforce/lwc-rfcs#63 . The reason I think so is because you're wanting to have slots inside of a for-loop and to pass for-loop-specific information into those slots (e.g. the current iteration index).

Closing as a duplicate of #210, please reopen if I'm mistaken.

@AllanOricil
Copy link
Contributor Author

@nolanlawson it is related, but I'm not sure if #210 would also expose this.slots in the parent js class. If it does, then you can keep this closed

@nolanlawson
Copy link
Collaborator

Hm, you're right, the proposal doesn't seem to allow programmatic access to the <slot> elements; in fact I believe they are not true <slot>s because native shadow DOM does not support scoped slots. Template refs (#2690) would also not address this since they are not true <slot>s.

@nolanlawson nolanlawson reopened this Aug 9, 2022
@AllanOricil AllanOricil closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2023
@nolanlawson nolanlawson reopened this Mar 3, 2023
@AllanOricil
Copy link
Contributor Author

AllanOricil commented May 14, 2023

Delivered 23 with scoped slots? @nolanlawson
I could not find docs saying that this.slots is accessible in the parent js

@AllanOricil AllanOricil reopened this May 14, 2023
@AllanOricil AllanOricil closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2023
@nolanlawson
Copy link
Collaborator

nolanlawson commented May 15, 2023

@AllanOricil It's true that we don't provide explicit access to slots. However, in native shadow you should be able to do this.template.querySelectorAll('slot') which gives the same thing.

For scoped slots, those are light DOM slots, and in the case of light DOM slots, I don't even know what it would mean to expose this.slots, since the slots are "virtual" and only really exist in the compiler. At runtime, there is no <slot> for light DOM.

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

No branches or pull requests

3 participants