A shared component works well until a product needs a slightly different trigger, layout or interaction. Then someone asks for asChild, a slot, or a render prop.
That can be the right extension point. But “bring your own element” is a larger promise than it looks.
Once consumers can replace part of a component, they also become part of its behaviour. The design system needs to say what the replacement must preserve.
The contract extends past the prop type
Consider a dialog trigger that accepts a product-owned button:
The example looks simple. The trigger supplies behaviour; the product supplies presentation. But ReviewButton sits between the primitive and the DOM.
Does it pass through the injected event handlers? Does the accessible name survive? Can a ref reach the interactive element? Does it still render an element with the right keyboard behaviour?
Radix’s composition guide makes these responsibilities explicit: custom leaf components need to spread the received props and support the ref expected by the primitive. It also leaves consumers responsible for preserving appropriate accessibility when changing the underlying element. Radix composition
A component can satisfy a TypeScript interface and still drop an important prop at runtime. The type is one part of the contract. The rendered behaviour is the part the user encounters.
Document what can change and what must survive
I’d describe an escape hatch in two short lists.
You can change: the visual treatment, icon placement, product-specific label and supported underlying element.
You must preserve: an accessible name, the appropriate interactive semantics, injected props, the ref path required by the primitive, and the documented event-composition behaviour.
The exact lists depend on the component. A navigation link and an action button do not have interchangeable semantics. A disabled link also needs a deliberate policy; forwarding a button’s disabled prop onto an anchor does not make it a disabled button.
This is where examples help more than an enormous union of permitted props. Show one supported custom button, one supported link where that makes sense, and one rejected composition. Explain the boundary.
Event ordering deserves an explicit decision
A consumer might attach an onClick handler that calls preventDefault(). Does that cancel the primitive’s action, or does the primitive still run?
There is no useful universal answer for every component library. Radix Slot documents its own rule: it composes event handlers with the child handler taking precedence, and warns that ordering matters when a handler checks defaultPrevented. Radix Slot
For an application wrapper, decide what cancellation means before callers start depending on accidental ordering. If a handler cancels an action, the test should verify the observable result, such as a dialog staying closed. A test that merely counts callbacks can miss the behaviour the caller intended to control.
Also distinguish cancellation from error handling. A thrown error should not quietly become your component’s supported way to cancel an interaction.
Test the seam, not every possible child
An escape hatch creates too many combinations to test exhaustively. A small contract fixture is more useful than pretending every child works.
For a composed dialog trigger, I’d keep a fixture with a custom leaf component and check:
- It has the expected accessible name and role.
- Keyboard activation opens the dialog.
- Focus moves into the dialog and returns appropriately when it closes.
- Consumer and primitive handlers cooperate according to the documented cancellation rule.
- The supported ref reaches the intended DOM element.
- An unsupported non-interactive child is rejected or clearly documented as unsupported.
The WAI-ARIA dialog pattern describes the expected keyboard and focus behaviour for modal dialogs, including focus management when opening and closing. Use it to choose observable expectations, then test the implementation you actually ship. WAI-ARIA modal dialog pattern
Storybook interaction tests can exercise component stories with simulated user interactions and assertions. That makes a contract fixture useful both as an example and as a regression check. It does not replace testing the real browser behaviour or a wider accessibility review. Storybook interaction testing
Keep the ref guidance version-aware
Avoid turning an implementation detail into a permanent rule. React 19 allows ref as a prop; React’s documentation says forwardRef is no longer necessary for that version. Older supported React versions and a library’s actual API may still require it. React forwardRef
The durable requirement is that the primitive gets the element reference it needs. The implementation should match the React and library versions your package supports.
Flexibility needs ownership
A useful escape hatch gives a product team room to adapt the UI without forcing it to rebuild the interaction. That only works when the boundary is understandable.
Before adding another slot or asChild option, write down what callers may replace, what they must preserve, and what happens when both sides handle the same event. Then give those decisions a small set of tests.
That is a more useful promise than “you can render anything.”
