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

Move slot attribute to <picture> element? #241

Open
tylersticka opened this issue Aug 17, 2024 · 0 comments
Open

Move slot attribute to <picture> element? #241

tylersticka opened this issue Aug 17, 2024 · 0 comments

Comments

@tylersticka
Copy link

tylersticka commented Aug 17, 2024

On my personal blog, I have a few posts that use my company's image comparison web component. Here's some simplified markup for that:

<image-compare>
  <img slot="image-1" alt="Alt Text" src="image-1.jpg" />
  <img slot="image-2" alt="Alt text" src="image-2.jpg" />
</image-compare>

When the Image Transform plugin processes these images with multiple formats, it creates <picture> elements (🎉). But there's a small problem with that in this particular case:

<image-compare>
  <picture>
    <source type="image/webp" srcset="image-1.webp 1920w">
    <img slot="image-1" alt="Alt Text" src="image-1.jpg" />
  </picture>
  <picture>
    <source type="image/webp" srcset="image-2.webp 1920w">
    <img slot="image-2" alt="Alt Text" src="image-2.jpg" />
  </picture>
</image-compare>

The attributes on the <img> element stick with said element, which makes sense 99% of the time. But in this case, the web component breaks unless the slot attribute is on the <picture> itself (<picture slot="image-1">).

I couldn't see a way to specify which attributes should stick with <img> versus <picture>. I tried adding a <picture> element with a slot ahead of time, but it looks like that won't be a feasible fix until/unless #214 is addressed. In the meantime I'm going to put eleventy:ignore on these for now, but figured I'd create an issue. ❤️

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

1 participant