Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StencilJS: Optional <slot /> element doesn’t work in IE11/Edge

I wrote a web component with StencilJS.

A slotted element should only be rendered in a specific case. So there is a optional element.

<div>
  <slot name="title"/>
    {this.active && (<slot name="content"/>)}
</div>

The call of the web component is the following:

<my-test>
   <div slot="title">This is a test</div>
   <div slot="content">123</div>
</my-test>

This doesn't work in Microsoft Edge und IE11. For Chrome and Firefox everything is fine.

I know slot's are not supported: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot#Browser_compatibility

But apparently there are some polyfills in stenciljs.

Chrome: Rendered in Chrome

IE11: Rendered in IE11

Are there any experiences about that topic?

like image 755
JV3 Avatar asked Oct 16 '22 15:10

JV3


1 Answers

As a workaround, instead of making the slot conditional (which IE won't respect), hide the slot conditionally:

<div>
  <slot name="title"/>
  <div style={!this.active && { 'display': 'none' }}>
    <slot name="content"/>
  </div>
</div>
like image 69
G. Tranter Avatar answered Nov 15 '22 06:11

G. Tranter