question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[labs/react] Support adding children to multiple slots

See original GitHub issue

Description

Currently, the react wrapper supports adding children to a default slot.

In order to support multiple slots from react -> lit wrapper, the react dev might have to wrap their components in an html element as an attribute.

() => (
  <div slot="slotA">
    <MyReactComponent />
  </div>
  <div slot="slotB">
    <MyReactComponent />
  </div>
  </div slot="slotC">
    <MyReactComponent />
  </div>
)

It’d be nice to support multiple slots in a shallow manner with react

export const MyElementComponent = createComponent(
  React,
  'my-element',
  MyElement,
  {
    onChange: 'input',
  },
  {
    propName: 'slot_name',
    icons: 'icons',
    suffix: 'suffix',
  }
);

However, rendering might be an issue between react and lit. The major hurdle is setting the slot attribute on an html element rendered in react.

Acceptance criteria

  1. Decide if this is a feature the labs react wrapper should support

  2. If we go forward, we need to agree on how to extend our API

  3. Provably use slotted react components in multiple web component slots

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bugwheels94commented, Jun 2, 2022

oh nice! display: contents will work with primitives, document fragments </> etc and is just better. I use a custom implementation of createReactComponent and I will try contents as I dont need to IE11.

1reaction
justinfagnanicommented, Jun 1, 2022

Setting the style to display: contents will keep the wrapper from interfering with styles.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass Multiple Children to a React Component with Slots
This component needs to be able to accept multiple children and place them in the layout as it sees fit – not right...
Read more >
First Lit & Friends Community Call! · Discussion #2986 - GitHub
Work in progres for this in [@labs/react] support multiple children with multiple slots #2985; We could also consider adding slotted content constraint ...
Read more >
Lit for React Developers - Google Codelabs
Lit is a simple library for building fast, lightweight web components that work in any framework, or with no framework at all. With...
Read more >
Component composition / Slots • Svelte Tutorial
Before a component can accept children, though, it needs to know where to put them. We do this with the <slot> element. Put...
Read more >
Building Interoperable Web Components That Work | CSS-Tricks
Those of us who've been web developers more than a few years have probably written code using more than one JavaScript framework.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found