Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ayloncarrijo
Copy link

@ayloncarrijo ayloncarrijo commented Jun 9, 2023

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>
  );
}

@jjenzz
Copy link
Contributor

jjenzz commented Jun 29, 2023

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.

@mskelton
Copy link

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?

@ahmadghoniem
Copy link

any updates on this?

@rrmesquita
Copy link

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

@joe-bell
Copy link

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

@mehdibha
Copy link

Any updates on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slot usage with nested children
7 participants