Skip to content

MenuItem — composition over configuration #96202

Description

@melvin-bot

Problem

The MenuItem component has ~130 props. We're actively decomposing large components like this, so it's a perfect candidate — e.g. 10+ icon-related props, plus tooltip logic, both extractable once it follows composition. It's the same compound pattern we already use for Button and Table.

Proposed Solution

Adopt a compound component pattern with a granular interface (flexibility for complicated cases) and a few presets covering the majority of the app.

Proposed API

<MenuItem.Root>
    <MenuItem.Label />
    <MenuItem.Row>
        <MenuItem.Icon />
        <MenuItem.Content>
            <MenuItem.Description />
            <MenuItem.Title />
        </MenuItem.Content>
        <MenuItem.Trailing>
            <MenuItem.Badge />
            <MenuItem.BrickRoadIndicator />
            <MenuItem.Chevron />
        </MenuItem.Trailing>
    </MenuItem.Row>
    <MenuItem.Error />
    <MenuItem.Hint />
</MenuItem.Root>

Presets

  • Extract MenuItemStandard (name TBD)
  • Update existing MenuItemWithTopDescription
  • These two presets should cover 80%+ of use cases; the rest will get dedicated presets or use the refactored MenuItem directly

Backwards compatibility

  • The existing <MenuItem title icon … /> API stays as-is — nothing breaks
  • Migration is incremental by deprecating the old component

Benefits

  • Stops new props being added every time a part of the item needs customising
  • Reduces rerenders across the app
  • Improves maintainability
  • Removes dead features (e.g. shouldPutLeftPaddingWhenNoIcon)
Issue OwnerCurrent Issue Owner: @Pujan92

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions