Skip to content

fix(dialog): not moving focus to container if autoFocus is disabled and focus was moved from a different component #16221

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
merged 1 commit into from
Jun 11, 2019

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jun 6, 2019

Given an example where we have a mat-menu that opens a dialog with autoFocus = false, the user's focus will end up on the menu's trigger, rather than the dialog container. This is due to the fact that we move focus to the dialog container immediately when the opening sequence starts and we assume that it's going to stay there. This isn't a problem when autoFocus is enabled, because we also try to move focus once the animation is done. These changes add an extra call after the animation finishes to ensure that the container has focus.

Note: I wasn't able to capture this properly in a unit test, because we need to be able to flush a Promise.resolve, followed by some logic which is then followed by flushing the animations. The problem is that I always ended up flushing the promise and the animations at the same time.

Fixes #16215.

…nd focus was moved from a different component

Given an example where we have a `mat-menu` that opens a dialog with `autoFocus = false`, the user's focus will end up on the menu's trigger, rather than the dialog container. This is due to the fact that we move focus to the dialog container immediately when the opening sequence starts and we assume that it's going to stay there. This isn't a problem when `autoFocus` is enabled, because we also try to move focus once the animation is done. These changes add an extra call after the animation finishes to ensure that the container has focus.

Fixes angular#16215.
@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Jun 6, 2019
@crisbeto crisbeto requested a review from jelbourn as a code owner June 6, 2019 16:51
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 6, 2019
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 labels Jun 7, 2019
@mmalerba mmalerba merged commit 2e047b4 into angular:master Jun 11, 2019
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jun 14, 2019
… inside the dialog

This is a follow-up to angular#16221. What we hadn't accounted for in the aforementioned PR is that the consumer may have turned off `autoFocus` so that they can handle it themselves and with our changes focus would be reset back to the container. These changes add an extra check which will ensure that focus is only moved if it's not inside the dialog already.
RudolfFrederiksen pushed a commit to RudolfFrederiksen/material2 that referenced this pull request Jun 21, 2019
…nd focus was moved from a different component (angular#16221)

Given an example where we have a `mat-menu` that opens a dialog with `autoFocus = false`, the user's focus will end up on the menu's trigger, rather than the dialog container. This is due to the fact that we move focus to the dialog container immediately when the opening sequence starts and we assume that it's going to stay there. This isn't a problem when `autoFocus` is enabled, because we also try to move focus once the animation is done. These changes add an extra call after the animation finishes to ensure that the container has focus.

Fixes angular#16215.
andrewseguin pushed a commit that referenced this pull request Jun 26, 2019
… inside the dialog (#16297)

This is a follow-up to #16221. What we hadn't accounted for in the aforementioned PR is that the consumer may have turned off `autoFocus` so that they can handle it themselves and with our changes focus would be reset back to the container. These changes add an extra check which will ensure that focus is only moved if it's not inside the dialog already.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jul 1, 2019
…bled and focus was moved while animating

These changes incorporate angular#16297 and angular#16221 into the bottom sheet since it follows a similar focus capturing behavior to `MatDialogContainer`. They ensure that focus is on the bottom sheet container when the animation is over, because it could've moved while we were animating. It also has an extra check to ensure that we don't move focus unnecessarily if the consumer decided to move focus themselves somewhere within the bottom sheet.
andrewseguin pushed a commit that referenced this pull request Jul 2, 2019
…nd focus was moved from a different component (#16221)

Given an example where we have a `mat-menu` that opens a dialog with `autoFocus = false`, the user's focus will end up on the menu's trigger, rather than the dialog container. This is due to the fact that we move focus to the dialog container immediately when the opening sequence starts and we assume that it's going to stay there. This isn't a problem when `autoFocus` is enabled, because we also try to move focus once the animation is done. These changes add an extra call after the animation finishes to ensure that the container has focus.

Fixes #16215.
andrewseguin pushed a commit that referenced this pull request Jul 2, 2019
… inside the dialog (#16297)

This is a follow-up to #16221. What we hadn't accounted for in the aforementioned PR is that the consumer may have turned off `autoFocus` so that they can handle it themselves and with our changes focus would be reset back to the container. These changes add an extra check which will ensure that focus is only moved if it's not inside the dialog already.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jul 3, 2019
…is disabled and focus was moved while animating

These changes incorporate angular#16297 and angular#16221 into the experimental dialog since it follows a similar focus capturing behavior to `MatDialogContainer`. They ensure that focus is on the dialog container container when the animation is over, because it could've moved while we were animating. It also has an extra check to ensure that we don't move focus unnecessarily if the consumer decided to move focus themselves somewhere within the container.
jelbourn pushed a commit that referenced this pull request Jul 9, 2019
…is disabled and focus was moved while animating (#16446)

These changes incorporate #16297 and #16221 into the experimental dialog since it follows a similar focus capturing behavior to `MatDialogContainer`. They ensure that focus is on the dialog container container when the animation is over, because it could've moved while we were animating. It also has an extra check to ensure that we don't move focus unnecessarily if the consumer decided to move focus themselves somewhere within the container.
jelbourn pushed a commit that referenced this pull request Jul 17, 2019
…bled and focus was moved while animating

These changes incorporate #16297 and #16221 into the bottom sheet since it follows a similar focus capturing behavior to `MatDialogContainer`. They ensure that focus is on the bottom sheet container when the animation is over, because it could've moved while we were animating. It also has an extra check to ensure that we don't move focus unnecessarily if the consumer decided to move focus themselves somewhere within the bottom sheet.
jelbourn pushed a commit that referenced this pull request Jul 19, 2019
…bled and focus was moved while animating (#16418)

These changes incorporate #16297 and #16221 into the bottom sheet since it follows a similar focus capturing behavior to `MatDialogContainer`. They ensure that focus is on the bottom sheet container when the animation is over, because it could've moved while we were animating. It also has an extra check to ensure that we don't move focus unnecessarily if the consumer decided to move focus themselves somewhere within the bottom sheet.
andrewseguin pushed a commit that referenced this pull request Jul 29, 2019
…bled and focus was moved while animating (#16418)

These changes incorporate #16297 and #16221 into the bottom sheet since it follows a similar focus capturing behavior to `MatDialogContainer`. They ensure that focus is on the bottom sheet container when the animation is over, because it could've moved while we were animating. It also has an extra check to ensure that we don't move focus unnecessarily if the consumer decided to move focus themselves somewhere within the bottom sheet.
@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 10, 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 P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Focus set incorrectly when opening dialog from menu
4 participants