Skip to content

Declare which slot is a component's children, rather than inferring it from the prop name #360

Description

@nathanacurtis

Problem

A component's primary slot is treated as "children" only when Figma happens to name the prop children. Any other name — items, content — is treated as a secondary slot, which is an accident of authoring rather than a statement of intent.

Consequences on both surfaces:

  • React consumers pass a fragment to a named prop instead of nesting children:

    <AvatarGroup items={<><Avatar/><Avatar/></>} />   // today
    <AvatarGroup><Avatar/><Avatar/></AvatarGroup>     // intended
  • Web Components emit a NAMED slot, so projected content must sit inside a holder carrying slot="items". The holder is then the only assigned node, and ::slotted() cannot style a slotted node's descendants — so the component cannot style its own projected children at all.

That last point already forced a workaround: a component whose slot children overlap (negative item spacing) cannot express it in its stylesheet, so the margin is inlined onto generated example content and is absent for real consumers.

Solution

The workspace declares which slot prop is a component's children. One declaration, two platform behaviours:

  • Web Components emit an unnamed <slot>; consumers write plain children, and every child is an assigned node reachable by ::slotted()
  • React emits the prop as children; consumers nest

Likely per-component rather than one workspace-wide name, since components name their primary slot differently.

Acceptance criteria

  • A slot declared as children projects through the default slot in web components
  • The same slot is exposed as children in React
  • Undeclared slots keep today's named behaviour
  • A component with declared children can style its projected children from its own stylesheet
  • Overlapping slot content works for a real consumer, not only generated examples

Workspace

Surfaced during component-by-component polish of React and web component output, reviewing both builds side by side in one Storybook.

Impacted code

  • conventions config and its schema
  • slot emission in both transform packages
  • slot content composition in both packages
  • the css transform's overlap rule, which can drop its inline workaround once children are reachable

Notes

Inferring from the prop name is the same class of fragility as keying off how many slots a component has: both make consumer markup depend on something unrelated to intent.


Implementation details are tracked internally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

react-from-specsTransformer from specs into React code

Type

No type

Fields

Priority

High

Projects

  • Status
    Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions