Skip to content

fix(menu): place submenu on left when no room on right#22261

Merged
maradwan26 merged 4 commits into
carbon-design-system:mainfrom
wkeese:wkeese/submenu
May 15, 2026
Merged

fix(menu): place submenu on left when no room on right#22261
maradwan26 merged 4 commits into
carbon-design-system:mainfrom
wkeese:wkeese/submenu

Conversation

@wkeese

@wkeese wkeese commented May 14, 2026

Copy link
Copy Markdown
Contributor

Closes #22252.

Description

Place submenu on left when no room on right.

Also fix alignment of menu when on the left. IMO we want the left submenu and right submenu to appear in mirror positions. According to https://floating-ui.com/docs/offset a simple setting like this should do that, regardless of which side the menu appears on:

middleware: [offset({ mainAxis: 6, crossAxis: -6 })],

But for some reason that doesn't work. I needed to adjust the mainAxis setting depending on whether the menu is to the left or right.

Before:
RTL before

After:

RTL after

Changelog

Changed

  • Submenus appear on the left when there's no room on the right.
  • Adjusted layout so a submenu on the left no longer overlaps the main menu. This mirrors the behavior when the submenu is on the right.

Testing / Reviewing

You can check the alignment on Storybook in RTL mode (https://react.carbondesignsystem.com/?path=/story/components-menu--default&globals=dir:rtl), and you can also use Storybook (or my Stackblitz) to check the flipping behavior by tweaking the main menu to appear at the right of the viewport.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

Also fix alignment of menu when on the left.  IMO we want the left submenu and
right submenu to appear in mirror positions.  According to
https://floating-ui.com/docs/offset a simple setting like this should do that,
regardless of which side the menu appears on:

middleware: [offset({ mainAxis: 6, crossAxis: -6 })],

But for some reason that doesn't work. I needed to adjust the mainAxis
setting depending on whether the menu is to the left or right.

Fixes #22252.
@wkeese wkeese requested a review from a team as a code owner May 14, 2026 01:09
@wkeese wkeese requested review from heloiselui and maradwan26 May 14, 2026 01:09
@netlify

netlify Bot commented May 14, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ea19d5f
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6a06fbf1632976000895e0c7
😎 Deploy Preview https://deploy-preview-22261--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 14, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit ea19d5f
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6a06fbf150573400080954b2
😎 Deploy Preview https://deploy-preview-22261--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.49%. Comparing base (6c33f63) to head (ea19d5f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #22261   +/-   ##
=======================================
  Coverage   95.49%   95.49%           
=======================================
  Files         582      582           
  Lines       50389    50391    +2     
  Branches     6787     6786    -1     
=======================================
+ Hits        48119    48121    +2     
  Misses       2138     2138           
  Partials      132      132           
Flag Coverage Δ
main-packages 89.18% <100.00%> (+<0.01%) ⬆️
web-components 98.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@netlify

netlify Bot commented May 15, 2026

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 9d5ede5
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6a06e3ae0271d3000809ace5
😎 Deploy Preview https://deploy-preview-22261--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@heloiselui heloiselui 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.

LGTM!

@wkeese

wkeese commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

OK thanks. It's too bad that this isn't covered in https://carbondesignsystem.com/components/menu/usage/#submenus (neither how it should look in RTL nor how it should look in LTR but when you just have to put the submenu on the left because there's no space on the right).

@heloiselui

heloiselui commented May 15, 2026

Copy link
Copy Markdown
Contributor

Yeah, the only info is in https://carbondesignsystem.com/components/menu/usage/#submenus:~:text=and%20selected%20items-,Right%20to%20left%20(RTL),-For%20RTL%20(right

@wkeese it seems a test is failing, could you check this? I’ll update the branch again just to check if it’s not a false failure.

@wkeese

wkeese commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, are you talking about this?

FAIL packages/react/src/components/ComboBox/ComboBox-test.js (39.196 s)
  ● ComboBox › should call `onChange` each time an item is selected

    TypeError: ace_ibma.Checker is not a constructor

I'm assuming that's an issue with the CI system as I didn't touch Combobox or accessibility stuff. It runs correctly for me locally:

% npx jest packages/react/src/components/ComboBox/ComboBox-test.js

@heloiselui

heloiselui commented May 15, 2026

Copy link
Copy Markdown
Contributor

Looks like is this: https://github.com/carbon-design-system/carbon/actions/runs/25914187255/job/76166599813?pr=22261

image

We could also add some tests to avoid this happening in the future.

@alina-jacob alina-jacob 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.

Looks good visually! 🚀

@wkeese

wkeese commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

Looks like is this: https://github.com/carbon-design-system/carbon/actions/runs/25914187255/job/76166599813?pr=22261

Presumably, another spurious failure unrelated to my change. I'm not sure how to trigger a rebuild besides waiting for someone else to merge a PR and then clicking the update button.

@maradwan26

Copy link
Copy Markdown
Contributor

Yeah, the test failure is unrelated to this PR. The ModalWrapper test has been having flakiness issues in some other PRs as well.

@maradwan26 maradwan26 enabled auto-merge May 15, 2026 14:51
@maradwan26 maradwan26 added this pull request to the merge queue May 15, 2026
Merged via the queue into carbon-design-system:main with commit 84de066 May 15, 2026
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: nested menus go off screen

4 participants