Element for <slot>?
Is it possible to not pass a wrapper element to a
<slot />
?
It looks like I have to use a wrapper element, otherwise I couldnt define the slot
attribute for my child.
Is there something like a fragment element?7 Replies
Do you have example markup and/or js?
https://jsfiddle.net/hndqb12s/1/
Here I must use a wrapping element (
<div>
) to apple the title to the slot. Now the html structure is
But I want its like
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
appending children is pretty easy. I see the issue now, you don't want a div element in the shadow dom. It looks like it needs some element container to be there at all, see this:
I added a new element to the slot without issue. Then I tried to reassign the slot, but the custom element doesn't redefine at the last line
comment out the last line because i broke it, then the elements are added in. the wrapper is defined in the custom element, though
It is not recommended to use innerHtml with user generated content. This can lead to XSS vulnerability.
that's a good catch, Aoi. I'm vulnerable to cross site scripting here because I used it in a global scope.
--> the comment out will fix that 😄