-
Notifications
You must be signed in to change notification settings - Fork 49
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
Event from parent to child (v1.6.0) #309
Comments
iamgpe
changed the title
Event from parent to child (v 1.6.0)
Event from parent to child (v1.6.0)
Mar 10, 2023
This workaround is ugly but it work: In your dom <parent-component>
<child-component data-targets="parent-component.bubbleables">
<!-- some code here -->
</child-component>
</parent-component> In your parent component import { controller, targets } from "@github/catalyst";
@controller
class ParentComponentElement extends HTMLElement {
@targets bubbleables!: HTMLElement[];
// call when you need to dispatch event to child
private dispatchEventToBubbleables(eventName: BusEvents): void {
const event = new CustomEvent(eventName);
this.bubbleables.forEach((element) => element.dispatchEvent(event));
}
} In your child components import { controller } from "@github/catalyst";
@controller
class ChildrenComponentElement extends HTMLElement {
connectedCallback(): void {
this.addEventListener('eventName', this.doSomething);
}
private doSomething(): void {
console.log('event received 🤩🤩🤩');
}
} |
Thanks for the issue! Events should only go upwards, from children to parents. Parents can use direct communication via the child’s API - directly calling methods and accessing properties. You can use targets to help easily query child components and use their class methods. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I try to retrieve an event from a component declared as parent (or parent of parent, etc..), the child component doesn't seem to want to retrieve it.
It would be nice to have a feature that would allow to trigger an event launched in a parent component in a child.
I haven't found an equivalent way to do this kind of thing on catalyst, but it would be nice to have this kind of feature.
The text was updated successfully, but these errors were encountered: