Allow nested sub-menus in the ActionMenu component #3564
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
This PR adds multi-level support to the
ActionMenu
component. It enables menus to be nested inside other menus just as can be done for the corresponding React component.Since there was no reason to build it, and because it's not clear how it should work,
ActionMenu
s with sub-menus do not support single-select mode.Screenshots
Alt: A screen recording initially showing only a button labeled "Edit." When the button is clicked, an
ActionMenu
appears containing three items: "Cut," "Copy," and "Paste special." The last item's label is followed by a right-facing chevron icon. This last item is clicked, which causes a sub-menu to appear to the right. This sub-menu contains four items, the last of which also features a right-facing chevron icon. When the last item is clicked, a third sub-menu appears containing 3 additional items. The last item is clicked and all three menus disappear.action_menu.mov
Integration
Multi-level support has been designed to maintain feature parity with the current
ActionMenu
component so as to be entirely backwards-compatible, at least from an API perspective. The component should generate nearly identical markup with the minor exception of the newly added sub-menu item, which includes a nested<ul>
and<anchored-position>
.However, care should be taken when integrating these changes, since they do represent a significant re-architecting of the component's inner workings.
Risk Assessment
What approach did you choose and why?
This feature was built by introducing a new menu item class called
SubMenuItem
. This class represents the menu item element and renders aSubMenu
component that essentially contains anotherActionMenu
wrapped in its own<anchored-position>
. To share code between the primary menu and sub-menus, the original code from theActionMenu
class was moved into a base class namedMenu
, from which bothPrimaryMenu
andSubMenu
now inherit.Accessibility
Merge checklist