Skip to content

fix(overlay): always dispatch keyboard events to top overlay in OverlayKeyboardDispatcher #10807

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

Currently when dispatching events through the OverlayKeyboardDispatcher we try to match one of the overlays to the element that triggered the event. This is problematic, because some components will open an overlay, but will keep focus on the trigger element (e.g. mat-autocomplete and mat-select). These changes switch the logic so the keyboard events are always dispatched to the top-level overlay.

Fixes #10799.

@crisbeto crisbeto requested a review from jelbourn as a code owner April 11, 2018 19:40
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 11, 2018
@crisbeto crisbeto force-pushed the 10799/top-level-overlay-dispatch branch from 61841ad to d7b71fa Compare April 11, 2018 20:17
@@ -85,8 +73,8 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
/** Keyboard event listener that will be attached to the body. */
private _keydownListener = (event: KeyboardEvent) => {
if (this._attachedOverlays.length) {
// Dispatch keydown event to the correct overlay.
this._selectOverlayFromEvent(event)._keydownEvents.next(event);
// Dispatch the keydown event to the top overlay.
Copy link
Member

Choose a reason for hiding this comment

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

Expand this with the rationale for why we always use the most recently opened overlay?

@@ -86,28 +86,6 @@ describe('OverlayKeyboardDispatcher', () => {
button.parentNode!.removeChild(button);
});

it('should dispatch targeted keyboard events to the overlay containing that target', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Should there be a test case with multiple open overlays?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's one called should dispatch body keyboard events to the most recently attached overlay a bit above.

@crisbeto crisbeto force-pushed the 10799/top-level-overlay-dispatch branch from d7b71fa to 5a14063 Compare April 26, 2018 14:23
@crisbeto
Copy link
Member Author

Addressed the feedback @jelbourn.

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 jelbourn added pr: lgtm 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 review labels Apr 26, 2018
@ngbot
Copy link

ngbot bot commented Apr 26, 2018

I see that you just added the pr: merge ready label, but the following checks are still failing:
    failure status "ci/circleci: build" is failing
    failure status "continuous-integration/travis-ci/pr" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@andrewseguin
Copy link
Contributor

Can you see whats up with CircleCI breakage?

…ayKeyboardDispatcher

Currently when dispatching events through the `OverlayKeyboardDispatcher` we try to match one of the overlays to the element that triggered the event. This is problematic, because some components will open an overlay, but will keep focus on the trigger element (e.g. `mat-autocomplete` and `mat-select`). These changes switch the logic so the keyboard events are always dispatched to the top-level overlay.

Fixes angular#10799.
@crisbeto crisbeto force-pushed the 10799/top-level-overlay-dispatch branch from 5a14063 to 2ec751b Compare April 27, 2018 00:31
@crisbeto
Copy link
Member Author

Looks like it was a flake @andrewseguin. It went away after a rebase.

@andrewseguin andrewseguin merged commit d96fa07 into angular:master Apr 28, 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.

Opened option list of a mat-select within a mat-dialog only closes after dialog has disappeared
4 participants