Skip to content
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

fix(demo-app): fix aligned menu triggers and make page scrollable #8280

Merged
merged 1 commit into from
Nov 21, 2017

Conversation

willshowell
Copy link
Contributor

This change keeps the classlist up to date when the menu panel is repositioned due to scrolling.

Since the menu does not need a correct transform-origin during its exit animation, this is not really noticeable or necessary. However, some users may be looking for positioning classes, or the animation may change in the future.

It also adds a scrolling to the demo app and fixes a misused style.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 7, 2017
@@ -341,7 +343,8 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
const posX: MenuPositionX = change.connectionPair.overlayX === 'start' ? 'after' : 'before';
const posY: MenuPositionY = change.connectionPair.overlayY === 'top' ? 'below' : 'above';

this.menu.setPositionClasses(posX, posY);
// Note that the position changes may be outside the Angular zone
this._ngZone.run(() => this.menu.setPositionClasses(posX, posY));
Copy link
Contributor

Choose a reason for hiding this comment

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

Does markForCheck in the ChangeDetectorRef not work for this situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought detectChanges might work, but no.

The problem is that onPositionChange sometimes emits within and sometimes outside NgZone due to the scroll dispatcher. I don't have a complete grasp on it, and this might be better if onPositionChange always just emitted from within the zone instead of trying to bring it back in at the component level.

@crisbeto can you weigh in?

Copy link
Member

Choose a reason for hiding this comment

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

Ideally we should be consistent in terms of where the event is being emitted, however with the way things are set up at the moment (onPositionChange isn't really a "change" event but more of an "update" event since it emits even if the position didn't change) we'd end up hitting the zone for all scroll events. We can address it better once the new connected positioning is in.

Copy link
Member

Choose a reason for hiding this comment

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

It would be better at least to only enter the zone when posX or posY change

Copy link
Member

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

Code-wise it looks good, however I think that it could lead to some performance issues since the onPositionChange currently emits whenever the position is updated, even if it didn't change, which will cause us to hit the zone for every scroll event. That being said, the issue is in the ConnectedPositionStrategy, not in the code from this PR. It may be better to hold off until we make the event a little smarter.

@@ -341,7 +343,8 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
const posX: MenuPositionX = change.connectionPair.overlayX === 'start' ? 'after' : 'before';
const posY: MenuPositionY = change.connectionPair.overlayY === 'top' ? 'below' : 'above';

this.menu.setPositionClasses(posX, posY);
// Note that the position changes may be outside the Angular zone
this._ngZone.run(() => this.menu.setPositionClasses(posX, posY));
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we should be consistent in terms of where the event is being emitted, however with the way things are set up at the moment (onPositionChange isn't really a "change" event but more of an "update" event since it emits even if the position didn't change) we'd end up hitting the zone for all scroll events. We can address it better once the new connected positioning is in.

@willshowell
Copy link
Contributor Author

@crisbeto that sounds good - I didn't even notice it was emitting on every event. I'm happy to repurpose this to be for just updating the demo app.

Do you or @jelbourn have a design doc/canonical issue for tracking improvements to the strategy? I'd hate for some of these things to be forgotten once it is available.

@jelbourn
Copy link
Member

The new connected position strategy is tracked in #6534

@willshowell willshowell force-pushed the fix/menu-class-updates branch from d8a9818 to c6f1128 Compare November 10, 2017 20:59
@willshowell willshowell changed the title fix(menu): update classlist when repositioning occurs due to scroll fix(demo-app): fix aligned menu triggers and add make page scrollable Nov 10, 2017
@willshowell willshowell changed the title fix(demo-app): fix aligned menu triggers and add make page scrollable fix(demo-app): fix aligned menu triggers and make page scrollable Nov 10, 2017
@willshowell
Copy link
Contributor Author

This now only updates the menu demo flex styles and adds extra height to demo scrolling behavior.

Copy link
Member

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

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Nov 10, 2017
@jelbourn jelbourn merged commit 179445c into angular:master Nov 21, 2017
@willshowell willshowell deleted the fix/menu-class-updates branch November 21, 2017 18:35
@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 7, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants