Skip to content

Export defaultSlot in RAC or a way to workaround required slot errors #5671

@jrmyio

Description

@jrmyio

Provide a general summary of the feature here

We are using the Provider from react-aria-components to create our own components.

In order to allow components with and without slots inside a Provider we want to be able to configure the default so that we do not run into the error A slot prop is required.

However, since the default is a symbol and not exported in the react-aria-components we cannot use this pattern.

See:

export const defaultSlot = Symbol('default');

export {composeRenderProps, Provider, useContextProps, useSlottedContext} from './utils';

🤔 Expected Behavior?

Be able to use defaultSlot in custom components so we can prevent the error.

😯 Current Behavior

You run into an error A slot prop is required when not specifying a slot for a component while having siblings with slots.

💁 Possible Solution

When building our design system on top of RAC i felt that the slot errors are a quite the hassle. We've seen the errors come up multiple times and sometimes this was good and it catched a mistake on our part, but in general I think using a default empty object for the default instead of erroring out is a better default.

The other option is to add defaultSlot to react-aria-components exports to allow users to use the symbol just how RAC components uses it internally for its components.

🔦 Context

Sometimes we have buttons in our UI that have slots and are configured by a Provider higher up in the tree. Sometimes we have buttons that don't use context and thus don't have a slot.

We want to support both.

💻 Examples

Codesandbox example

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions