#Restrict `children` to single child that isn't a Fragment

1 messages · Page 1 of 1 (latest)

lofty spindle
#

Radix-UI has this concept of asChild where, when there's a Trigger component (e.g. a button that opens a modal), you can either just do:

<Modal.Trigger>
  Foo!
</Modal.Trigger>

In this instance, the Trigger will turn into a Button. Or you could do:

<Modal.Trigger asChild>
  <MyButton>Foo!</MyButton>
</Modal.Trigger>

Where the things that make the trigger work get put onto the button you put in.

However, if you use asChild, the child CAN NOT BE A FRAGMENT - there's nothing to spread the interactivity to in that case. Is there a way Radix-UI (or I for a similar component) can refuse React.Fragment as a valid child in this case?

I know we can restrict to a single child by using Children.only(children), but I don't know how to further restrict that to a non-fragment child.

lapis pier