Skip to content

fix(drawer): drawer running inside the zone keydown event. #10092

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

llorenspujol
Copy link
Contributor

Currently, the drawer is listening to the event 'keydown' inside the zone. This makes the change detector be fired every time while we are pressing 'any' key, even it's is not the ESCAPE key.
With this code, we can escape it, and run only inside the zone when there is an escape event.

Do we really need this?
I'm sure most apps would not need that, but for example, in our app, we have a drawer that inside has a bunch of controls that are controlled by keyboard events... so this has an impact to our performance since change detector is fired while pressing. So I think it would be a good change, although it's is not much elegant, but it is functional.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 22, 2018
@mmalerba
Copy link
Contributor

Interesting, had not considered this, good catch!

@@ -273,6 +274,16 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
this._restoreFocus();
}
});

// Handles the ESCAPE keyboard event
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you expand this comment a little bit to explain why we're doing it this way as opposed to just (keydown)

@llorenspujol llorenspujol force-pushed the fix-drawer-keydown-inside-zone branch from c1669ff to b036141 Compare February 23, 2018 08:41
@llorenspujol llorenspujol changed the title fix(drawe): drawer running inside the zone keydown event. fix(drawer): drawer running inside the zone keydown event. Feb 23, 2018
@llorenspujol
Copy link
Contributor Author

Thanks! I have updated the comment @mmalerba , what do you think?

@llorenspujol llorenspujol force-pushed the fix-drawer-keydown-inside-zone branch from b036141 to a0a54aa Compare February 23, 2018 10:08
@@ -273,6 +274,20 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
this._restoreFocus();
}
});

/**
* Runs outside the zone the 'keydown' event listener. This avoids change detector to be fired
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

/**
 * Listen to `keydown` events outside the zone so that change detection is not run every
 * time a key is pressed. Instead we re-enter the zone only if the `ESC` key is pressed
 * and we don't have close disabled.
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Currently the drawer is listening to the event 'keydown' inside the zone. This makes the change detector be fired every time while whe are pressing 'any' key.
@llorenspujol llorenspujol force-pushed the fix-drawer-keydown-inside-zone branch from a0a54aa to c08f00a Compare February 26, 2018 09:52
@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 26, 2018
@mmalerba
Copy link
Contributor

Thanks for the fix!

@crisbeto
Copy link
Member

@mmalerba this one's missing a release target.

@mmalerba mmalerba added the target: patch This PR is targeted for the next patch release label Feb 26, 2018
@mmalerba
Copy link
Contributor

marked it patch for now. If it turns out to break a bunch of tests because people were relying on this to trigger change detection we can up it to major

@tinayuangao tinayuangao merged commit 981c9a9 into angular:master Mar 1, 2018
tinayuangao pushed a commit that referenced this pull request Mar 5, 2018
Currently the drawer is listening to the event 'keydown' inside the zone. This makes the change detector be fired every time while whe are pressing 'any' key.
@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.

5 participants