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

Error after closing dialog in IE if there was no active element when opening the dialog #2760

Closed
basvandenberg opened this issue Jan 23, 2017 · 1 comment · Fixed by #2771
Assignees

Comments

@basvandenberg
Copy link

Bug, feature request, or proposal:

Bug.

What is the expected behavior?

Dialog closes without throwing a TypeError in IE (for dialog that was opened when there was no element with focus).

What is the current behavior?

I open a dialog by clicking an item in a drop down menu. This drop down menu is then closed immediately, which means that there is no element with focus. In dialog-container the element with focus is stored with:

this._elementFocusedBeforeDialogWasOpened = document.activeElement;

The document.activeElement documentation states that:

When there is no selection, the active element is the page's <body> or null.

I guess that both Chrome and Firefox set the <body> as active element, and IE sets it to null. Because only in IE I get the TypeError:

TypeError: Unable to get property 'focus' of undefined or null reference

When the dialog is trying to re-focus the element with last focus after closing the dialog:

(this._elementFocusedBeforeDialogWasOpened as HTMLElement).focus();

What are the steps to reproduce?

In IE, open dialog without an element having focus, close dialog again.

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

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

Affected browser: IE11.

Is there anything else we should know?

@crisbeto crisbeto self-assigned this Jan 23, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 23, 2017
* Adds an extra null check when restoring focus after a dialog is closed. This is necessary, because the `document.activeElement` can be null in IE.
* Switches the focusing logic to use the `Renderer`.

Fixes angular#2760.
@kara kara closed this as completed in #2771 Feb 1, 2017
@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants