primitives icon indicating copy to clipboard operation
primitives copied to clipboard

[Slot] Add support for nested children (#1825)

Open ayloncarrijo opened this issue 1 year ago • 6 comments

Description

This PR modifies the way Slottable works, adding support for nested children without the need to parse them.

Fixes #1825

Example

import React from 'react';
import { Slot, Slottable } from '@radix-ui/react-slot';

function Button({ asChild, children, ...props }) {
  const Component = asChild ? Slot : "button";

  return (
    <Component {...props}>
      <Slottable child={children}>
        {(child) => (
          <div>
            <div>icon</div>
            <div>{child}</div>
            <div>icon</div>
          </div>
        )}
      </Slottable>
    </Component>
  );
}

ayloncarrijo avatar Jun 09 '23 01:06 ayloncarrijo

i really like this 👍 it might be good to add a test that verifies a deeply nested tree works if you don’t mind @ayloncarrijo?

it will help flag an error in future if anyone tries to refactor and remove the child as func pattern.

jjenzz avatar Jun 29 '23 08:06 jjenzz

This PR is awesome, I copied this into a project of mine which needed this behavior. Anything I can do to help this PR move forward and get merged?

mskelton avatar Aug 17 '23 16:08 mskelton

any updates on this?

ahmadghoniem avatar Sep 06 '23 10:09 ahmadghoniem

I also copied this into a project and it works very nicely. I'm looking forward to seeing this merged. Thanks @ayloncarrijo !

rrmesquita avatar Sep 09 '23 00:09 rrmesquita

Swinging by to say thanks @ayloncarrijo: this worked a treat!

joe-bell avatar Mar 21 '24 15:03 joe-bell

Any updates on this PR?

mehdibha avatar Apr 16 '24 14:04 mehdibha