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

leverage <template> element for footer and header custom element examples #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

srpcoder
Copy link

@srpcoder srpcoder commented Mar 11, 2024

Changes were made in the DOM

resolves #84

Changes were made in the DOM
Copy link
Member

@thescientist13 thescientist13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @srpcoder and apologies for the delay in reviewing this.

Let me take a look at the build failure because it seems like this should work but the Netlify build does not seem to be happy for some reason. 🤔

@thescientist13 thescientist13 changed the title Made the chnages leverage <template> elements for footer and header custom element examples Apr 3, 2024
@thescientist13 thescientist13 added the enhancement New feature or request label Apr 3, 2024
@thescientist13 thescientist13 self-assigned this Apr 3, 2024
@thescientist13 thescientist13 changed the title leverage <template> elements for footer and header custom element examples leverage <template> element for footer and header custom element examples Apr 3, 2024
export default class FooterComponent extends HTMLElement {
// run some code to set HTML when the component is ready
connectedCallback() {
this.innerHTML = template.content.cloneNode(true);
Copy link
Member

@thescientist13 thescientist13 Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is breaking the build for me locally too and I think is just a mismatch between Light DOM / DSD.

But as a quick test, this would work

export default class HeaderComponent extends HTMLElement {
  connectedCallback() {
    this.innerHTML = template.innerHTML;
  }
}

Getting closer to DSD conventions this works...

export default class HeaderComponent extends HTMLElement {
  connectedCallback() {
    this.appendChild(template.content.cloneNode(true));
  }
}

However, this will render everything out into a DSD (e.g. <template shadowrootmode="open">...</template> (naturally) which is not really what we want here since we are explicitly looking to render out only to Light DOM for these components.


So yeah, I think this is the form we want to go with here

export default class HeaderComponent extends HTMLElement {
  connectedCallback() {
    this.innerHTML = template.innerHTML;
  }
}

edit: Not sure that will actually work, let me keep looking into this, will try and get a conclusive answer for you.

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

Successfully merging this pull request may close these issues.

use a <template> tag for header and footer components
2 participants