Skip to content

[RFC] Meaning of components and slots #34333

Closed
@siriwatknp

Description

@siriwatknp

What's the problem? 🤔

From #33416 and #21453, I feel that we are mixing slots and components together even though they are not the same.

By having an agreement on the meaning, I believe that it will be easier to decide on the APIs (to override components and slots).

What are the requirements? ❓

There are real use cases where you want to replace the component (HTML tag) or the slot.

Slot override

When: developers want to take control of the logic, and styles of the default slot.
Use case: GitHub label example, the popper's logic has to be replaced to show options below the input.

Component override

When: developers want to change the HTML tag, normally for accessibility. (component override is more common than slot override). Alternatively, they want to add custom logic by preserving the default styles.
Use case:

  • changing button to a
  • changing ul to div in the Autocomplete for grouped options
  • access ownerState and add some logic + styles.

Proposed solution 🟢

This can apply to MUI Base, Material UI and Joy UI.

Slots

All MUI components have at least 1 slot, aka root slot. The slot can be a string (DOM) or a styled component. In MUI Base, the slots are mostly strings because it is unstyled. However, for Material UI, Joy UI, the slots are mostly styled-components.

The name of the slot can be seen in the suffix of the className.

Components

Represents the HTML tag used in the slot. For example, Joy UI's Input has 2 slots (root and input):

  • The component of the root slot is <div>.
  • The component of the input slot is <input>.,

Resources and benchmarks 🔗

No response

Metadata

Metadata

Labels

RFCRequest For Comments

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions