4

I have created two web components that are nested together. The main problem that I am facing is when I try to render the child component, everything from the parent gets overlapped. I think that the issue is that both parent component and child component are rendering <slot/>. As you can see the parent component renders <slot></slot>. And the child component renders each of its slots by there name as well, the only "solution" that I found is to set shadow to true(shadow:true) in the child element, that way only the child <slot/> is shown and it doesn't get overlapped by the parent. But that is not working for me because inside my child component I would like to render another component, but since this is shadow DOM it does not show anything. Any ideas?, thanks.

<parent-component>
  <child-component>
    <div slot='title'>title</div>
    <div slot='subtitle'>subtitle</div>
  </child-component>
</parent-component>
@Component({
  tag: 'child-component'
  shadow: false
})
export class ChildComponent{

  //my-logic

  render(){
    return(
      <div>
        <slot name='title'/>
        <slot name='subtitle'/>
        <external-component></external-component>
      </div>
    )}
  }
}
@Component({
  tag: 'parent-component'
  shadow: false
})
export class ParentComponent{

  //my-logic

  render(){
    return(
      <div>
        <slot></slot>
      </div>
    )}
  }
}
Simon Hänisch
  • 4,740
  • 2
  • 30
  • 42
  • 1
    Which Stencil version are you using? There was a bug related to relocation of slot content in non-shadow components, I think it was fixed in Stencil 1.10 but can't remember exactly. – Simon Hänisch Apr 30 '20 at 17:07
  • IMHO overlapping sounds like it might be a CSS problem, not JS. – Thomas May 07 '20 at 16:32

0 Answers0