Skip to content

fix(menu): unable to open same sub-menu from different triggers and not picking up indirect descendant items #10132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

crisbeto
Copy link
Member

  • Reworks the relationship between the menu items and the menu panel to allow for the items to be indirect descendants of the menu, while also allowing for mat-menu instances to be declared inside of other mat-menu instances without having the root mat-menu pick up all of the descendant items.
  • Adds the ability to pass in an array to the ListKeyManager, in addition to a QueryList.
  • Fixes not being able to re-use the same sub-menu between multiple sub-menu triggers.

Fixes #9969.
Fixes #9987.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 24, 2018
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from a18d631 to a7a2ae6 Compare February 25, 2018 09:58
if (newIndex > -1 && newIndex !== this._activeItemIndex) {
this._activeItemIndex = newIndex;
constructor(private _items: QueryList<T> | T[]) {
if (_items instanceof QueryList) {
Copy link
Member

Choose a reason for hiding this comment

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

Add comment that explains why items can be either a QueryList or an array?

* Registers a menu item with the menu.
* @docs-private
*/
addItem(item: MatMenuItem) {
Copy link
Member

Choose a reason for hiding this comment

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

Does needing to call these methods constitute a breaking change for people implementing their own menu panel?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so. We never required the items (the QueryList we used before to collected the items) as a part of the MatMenuPanel and we didn't support custom menu panels for nested menus either.

@@ -294,6 +300,30 @@ export class MatMenu implements OnInit, AfterContentInit, MatMenuPanel, OnDestro
}
}

/**
* Registers a menu item with the menu.
Copy link
Member

Choose a reason for hiding this comment

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

Expand to talk about why this registration is necessary?

@@ -140,6 +143,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
@Optional() @Self() private _menuItemInstance: MatMenuItem,
@Optional() private _dir: Directionality,
// TODO(crisbeto): make the _focusMonitor required when doing breaking changes.
// @deletion-target 6.0.0
Copy link
Member

Choose a reason for hiding this comment

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

Is deletion target the right tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what we've been using in other places to mark that a parameter should become required. deletion-target might not be the best naming for it though.

// Since we might have multiple competing triggers for the same menu (e.g. a sub-menu
// with different data and triggers), we have to delay it by a tick to ensure that
// it won't be closed immediately after it is opened.
.pipe(filter(active => active === this._menuItemInstance), delay(0))
Copy link
Member

Choose a reason for hiding this comment

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

Will this delay trigger multiple change detections if you quickly hover over multiple menu items?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're triggering change detections anyway, because we have a mouseenter listener on each menu item.

@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from a7a2ae6 to 8643ddd Compare February 26, 2018 20:38
Copy link
Member Author

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

Addressed the feedback @jelbourn.

* Registers a menu item with the menu.
* @docs-private
*/
addItem(item: MatMenuItem) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so. We never required the items (the QueryList we used before to collected the items) as a part of the MatMenuPanel and we didn't support custom menu panels for nested menus either.

@@ -140,6 +143,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
@Optional() @Self() private _menuItemInstance: MatMenuItem,
@Optional() private _dir: Directionality,
// TODO(crisbeto): make the _focusMonitor required when doing breaking changes.
// @deletion-target 6.0.0
Copy link
Member Author

Choose a reason for hiding this comment

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

That's what we've been using in other places to mark that a parameter should become required. deletion-target might not be the best naming for it though.

// Since we might have multiple competing triggers for the same menu (e.g. a sub-menu
// with different data and triggers), we have to delay it by a tick to ensure that
// it won't be closed immediately after it is opened.
.pipe(filter(active => active === this._menuItemInstance), delay(0))
Copy link
Member Author

Choose a reason for hiding this comment

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

We're triggering change detections anyway, because we have a mouseenter listener on each menu item.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn
Copy link
Member

Just needs rebase

@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch 2 times, most recently from b0b7139 to d798784 Compare March 3, 2018 17:02
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed pr: needs rebase labels Mar 3, 2018
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from d798784 to c2a6a5d Compare March 11, 2018 02:05
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from c2a6a5d to dd5c23c Compare March 26, 2018 18:05
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch 2 times, most recently from 3f40dbc to 087ac4d Compare March 29, 2018 14:23
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from 087ac4d to 0df86e8 Compare April 8, 2018 12:50
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from 0df86e8 to 9b32c13 Compare April 14, 2018 13:11
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from 9b32c13 to 2c33108 Compare April 24, 2018 23:08
@andrewseguin andrewseguin added the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Apr 26, 2018
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch 2 times, most recently from 642bd06 to e71f2de Compare May 1, 2018 19:14
@josephperrott
Copy link
Member

@crisbeto Looks like this has a couple lint errors.

@josephperrott josephperrott added pr: needs cleanup / tests and removed action: merge The PR is ready for merge by the caretaker presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged labels May 1, 2018
…ot picking up indirect descendant items

* Reworks the relationship between the menu items and the menu panel to allow for the items to be indirect descendants of the menu, while also allowing for `mat-menu` instances to be declared inside of other `mat-menu` instances without having the root `mat-menu` pick up all of the descendant items.
* Adds the ability to pass in an array to the `ListKeyManager`, in addition to a `QueryList`.
* Fixes not being able to re-use the same sub-menu between multiple sub-menu triggers.

Fixes angular#9969.
Fixes angular#9987.
@crisbeto crisbeto force-pushed the 9987/nested-menu-multi-trigger branch from e71f2de to 9657ebe Compare May 1, 2018 21:52
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs cleanup / tests labels May 1, 2018
@crisbeto
Copy link
Member Author

crisbeto commented May 1, 2018

Fixed @josephperrott.

@josephperrott josephperrott merged commit 5393bfe into angular:master May 2, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with lazy rendered nested menus [bug mat-menu]: nested menu not closing when mat-menu-item is not directly inside mat-menu
5 participants