-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(drawer): drawer running inside the zone keydown event. #10092
Conversation
Interesting, had not considered this, good catch! |
src/lib/sidenav/drawer.ts
Outdated
@@ -273,6 +274,16 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr | |||
this._restoreFocus(); | |||
} | |||
}); | |||
|
|||
// Handles the ESCAPE keyboard event |
There was a problem hiding this comment.
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)
c1669ff
to
b036141
Compare
Thanks! I have updated the comment @mmalerba , what do you think? |
b036141
to
a0a54aa
Compare
src/lib/sidenav/drawer.ts
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
*/
There was a problem hiding this comment.
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.
a0a54aa
to
c08f00a
Compare
Thanks for the fix! |
@mmalerba this one's missing a release target. |
marked it |
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.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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.