Skip to content

refactor: MenuItem decomposition into a compound component - #96650

Draft
war-in wants to merge 28 commits into
Expensify:mainfrom
software-mansion-labs:war-in/menu-item-decomposition
Draft

refactor: MenuItem decomposition into a compound component#96650
war-in wants to merge 28 commits into
Expensify:mainfrom
software-mansion-labs:war-in/menu-item-decomposition

Conversation

@war-in

@war-in war-in commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Decomposes the monolithic MenuItem (~135 props) into a composable compound component. Consumers now assemble a row from sub-components (MenuItem.Row, .Icon, .Avatar, .Content, .Title, .Description, .Trailing, .Chevron, .BrickRoadIndicator, etc.), with interaction state (hover/press/focus/disabled) shared via MenuItemContext. Moves MenuItem into its own directory and migrates SettingsMenuItem to the new pattern as the first consumer.

Fixed Issues

$ #96202
PROPOSAL:

Tests

  1. Open the app and navigate to Settings (bottom tab / account menu).
  2. Verify the settings menu rows render correctly: leading avatar/icon, title, description, trailing chevron, and any brick-road indicators or badges are aligned and styled as before.
  3. Hover over a settings row (web) and verify hover styling applies (icon fill, chevron reveal, row background).
  4. Press a settings row and verify it navigates to the expected screen and the pressed styling appears.
  5. Verify a row that shows an error/brick-road indicator still displays the red/green dot and any error text.

Offline tests

N/A

QA Steps

Same as tests.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@war-in

war-in commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b26bd03727

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/MenuItem/MenuItem.tsx
Comment thread src/pages/settings/SettingsMenuItem.tsx Outdated
@war-in war-in closed this Jul 22, 2026
@war-in war-in reopened this Jul 22, 2026

@jmusial jmusial left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a first batch - will finish tomorrow

Comment thread src/components/MenuItem/MenuItemContext.tsx Outdated
Comment thread src/components/MenuItem/compound.tsx Outdated
Comment thread src/components/MenuItem/compound.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemContent.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemContent.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
const styles = useThemeStyles();
const {isDisabled, isCompact} = useMenuItemState();

return <View style={[styles.flexRow, styles.pointerEventsAuto, styles.gap3, isDisabled && styles.cursorDisabled, isCompact && styles.alignItemsCenter, style]}>{children}</View>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create named styles for componenets please - will look cleaner

Comment thread src/components/MenuItem/layout/MenuItemTrailing.tsx
Comment thread src/components/MenuItem/MenuItem.tsx
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx Outdated
Comment thread src/components/MenuItem/leaves/leading/MenuItemIcon.tsx Outdated
Comment thread src/CONST/index.ts
Comment thread src/components/MenuItem/leaves/trailing/MenuItemCopyButton.tsx
Comment on lines +40 to +42
/** Container variant. `default` reserves the classic fixed-width cell; `compact` hugs the icon.
* Rows inside a compact menu are compact regardless of this prop. */
variant?: MenuItemIconVariant;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe “size” would be a better name

Comment thread src/components/MenuItem/leaves/leading/MenuItemIcon.tsx

@Guccio163 Guccio163 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of work done, looks like we have a lot to go through; Here are some things that I've found, I'm open for a discussion.

BTW I feel like if you'd introduced some MenuItem-copy component that would in some way show which MenuItem fragments are being replaced with which primitives it would make comparison that easier, moreover we'd see in the migrated component which parts are still being used and need resolution. I would see it as a (f.ex.) nowhere-used MenuItemOld.tsx deprecated file next to the MenuItem.tsx, pushed before so it shows all changes, with code fragments replaced with exact primitives. LMKWYT 👀

Comment thread src/components/MenuItem/compound.tsx Outdated
Comment thread src/components/MenuItem/layout/MenuItemRoot.tsx
Comment thread src/pages/settings/SettingsMenuItem.tsx
Comment thread src/components/MenuItem/layout/MenuItemTrailing.tsx
Comment thread src/components/MenuItem/leaves/messages/MenuItemError.tsx Outdated
Comment thread src/components/MenuItem/leaves/text/MenuItemTitle.tsx
Comment thread src/components/MenuItem/leaves/messages/MenuItemHelperText.tsx Outdated
Comment thread src/components/MenuItem/leaves/trailing/MenuItemRightLabel.tsx
Comment thread src/components/MenuItem/leaves/text/MenuItemTitle.tsx Outdated
Comment thread src/components/MenuItem/leaves/text/MenuItemDescription.tsx
Comment thread src/components/MenuItem/compound.tsx Outdated

@JakubKorytko JakubKorytko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice decomposition, the leaf split reads well and the compiled files pass the React Compiler compliance check. A couple of small cleanups below that are additive to the feedback already left by other reviewers (I skipped the points already raised: the missing index.ts, and the many-props-on-Root discussion).

Comment thread src/CONST/index.ts
Comment thread src/pages/settings/InitialSettingsPage.tsx

@jmusial jmusial left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a different, more step by step approach to this refactor.
Right now half of the new components have no call sites, but bloat out the PR making it harder to review and will lengthen whole process.

How about @ first implementing only the components used in a particular migration use case and then adding them progressively while migrating following call sites ?

Would make PRs smaller and redundant props easier to spot

Comment thread src/components/MenuItem/leaves/leading/MenuItemAvatar.tsx
Comment thread src/components/MenuItem/leaves/leading/MenuItemAvatar.tsx
Comment thread src/components/MenuItem/leaves/messages/MenuItemHint.tsx Outdated
Comment thread src/components/MenuItem/leaves/trailing/MenuItemBadge.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants