Skip to content

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

@basvandenberg

Description

@basvandenberg

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions