Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(dialog): Release focus after style changes on close (#4069)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiomkar authored Nov 21, 2018
1 parent 857977f commit e12997a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/mdc-dialog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ a focus trapping solution for your component code.**

[focus-trap]: https://github.com/davidtheclark/focus-trap

> NOTE: iOS platform doesn't seem to register currently focused element via `document.activeElement` which causes releasing
> focus to last focused element fail.
#### `createFocusTrapInstance()`

```js
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-dialog/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class MDCDialogFoundation extends MDCFoundation {

this.isOpen_ = false;
this.adapter_.notifyClosing(action);
this.adapter_.releaseFocus();
this.adapter_.addClass(cssClasses.CLOSING);
this.adapter_.removeClass(cssClasses.OPEN);
this.adapter_.removeBodyClass(cssClasses.SCROLL_LOCK);
Expand All @@ -154,6 +153,7 @@ class MDCDialogFoundation extends MDCFoundation {

clearTimeout(this.animationTimer_);
this.animationTimer_ = setTimeout(() => {
this.adapter_.releaseFocus();
this.handleAnimationTimerEnd_();
this.adapter_.notifyClosed(action);
}, numbers.DIALOG_ANIMATION_CLOSE_TIME_MS);
Expand Down
7 changes: 7 additions & 0 deletions test/unit/mdc-dialog/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,15 @@ test('#close deactivates focus trapping on the dialog surface', () => {

foundation.open();
td.reset();

const clock = installClock();
foundation.close();

// Wait till setTimeout callback is executed.
clock.runToFrame();
clock.tick(100);
clock.tick(numbers.DIALOG_ANIMATION_OPEN_TIME_MS);

td.verify(mockAdapter.releaseFocus());
});

Expand Down

0 comments on commit e12997a

Please sign in to comment.