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

Support slots without shadow dom #37

Open
Machy8 opened this issue Jun 14, 2024 · 0 comments
Open

Support slots without shadow dom #37

Machy8 opened this issue Jun 14, 2024 · 0 comments

Comments

@Machy8
Copy link
Contributor

Machy8 commented Jun 14, 2024

The component will have to travers dom until it reaches another web component:

  • During this process, every slot will be replaced by a new one.
  • It will have to be connected to correct hook in the web component lifecycle (constructor vs connected).

Code from old prototype (it won't work anymore in current state):

const convertInnerHtmlToFragment = () => {
	const template = document.createElement('template');
	template.innerHTML = this.innerHTML.trim();
	return template;
}


if (options?.shadow) {
	if (template === undefined) {
		template = convertInnerHtmlToFragment();
		this.innerHTML = '';
	}
} else if (template !== undefined) {
	const fragment = convertInnerHtmlToFragment();

	for (const slot of fragment.querySelectorAll('[slot]')) {
		const slotName = slot.getAttribute('slot');
		slot.removeAttribute('slot');
		template.content.querySelector(`slot[name="${slotName}"]`)?.replaceWith(slot);
	}

	template.content.querySelector('slot:not([name])')?.replaceWith(currentTemplate.content);
}
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

1 participant