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

Need an option: don't restore focus after dialog is closed #12515

Closed
jasonzhang2022 opened this issue Aug 3, 2018 · 2 comments · Fixed by #12519
Closed

Need an option: don't restore focus after dialog is closed #12515

jasonzhang2022 opened this issue Aug 3, 2018 · 2 comments · Fixed by #12519
Assignees
Labels
G This is is related to a Google internal issue

Comments

@jasonzhang2022
Copy link

feature request

be able to tell Mat-dialog that it should not restore focus after it is closed. This can be passed as an option to mat-dialog.open(componentRef, {returnFocus:false})

What is the expected behavior?

Mat-Dialog doesn't try to return focus or manage focus

What is the current behavior?

"Once a dialog is closed, it will return focus to the element that was focused before the dialog was opened."

What are the steps to reproduce?

This is default behavior. Any mat-dialog behaves like this right now.

What is the use-case or motivation for changing an existing behavior?

I have a spinner/loading service. The spinner service is used like this
spinner.show(), spinner.hide(). Spinner service uses mat-dialog as internal implementation.

Usually, spinner.show() is called before page switch when a menu button is clicked. Spinner.hide() is called by the new page when data is ready.

My page has a directive similar to cdkFocusInitial. The directive puts focus into correct element in current page declaratively. However when data is ready and dialog is closed, mat-dialog returns focus to menu button.

If I can pass an option like this, dialog.open(spinner, {returnFocus: false} ), my directive will work properly. Page focus can be managed by directive.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

all

Is there anything else we should know?

None

@josephperrott josephperrott added the G This is is related to a Google internal issue label Aug 3, 2018
@crisbeto crisbeto closed this as completed Aug 3, 2018
@crisbeto crisbeto reopened this Aug 3, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 3, 2018
Allows for the dialog focus restoration to be opted out of, in case the consumer wants to handle it themselves.

Fixes angular#12515.
@crisbeto crisbeto self-assigned this Aug 3, 2018
@crisbeto crisbeto added the has pr label Aug 3, 2018
@julianobrasil
Copy link
Contributor

@crisbeto, is it possible to extend this feature to mat-bottom-sheet, mat-datepicker and mat-menu?

@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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
G This is is related to a Google internal issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants