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

Commit e12997a

Browse files
authored
fix(dialog): Release focus after style changes on close (#4069)
1 parent 857977f commit e12997a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/mdc-dialog/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ a focus trapping solution for your component code.**
436436

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

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

441444
```js

packages/mdc-dialog/foundation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class MDCDialogFoundation extends MDCFoundation {
144144

145145
this.isOpen_ = false;
146146
this.adapter_.notifyClosing(action);
147-
this.adapter_.releaseFocus();
148147
this.adapter_.addClass(cssClasses.CLOSING);
149148
this.adapter_.removeClass(cssClasses.OPEN);
150149
this.adapter_.removeBodyClass(cssClasses.SCROLL_LOCK);
@@ -154,6 +153,7 @@ class MDCDialogFoundation extends MDCFoundation {
154153

155154
clearTimeout(this.animationTimer_);
156155
this.animationTimer_ = setTimeout(() => {
156+
this.adapter_.releaseFocus();
157157
this.handleAnimationTimerEnd_();
158158
this.adapter_.notifyClosed(action);
159159
}, numbers.DIALOG_ANIMATION_CLOSE_TIME_MS);

test/unit/mdc-dialog/foundation.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,15 @@ test('#close deactivates focus trapping on the dialog surface', () => {
205205

206206
foundation.open();
207207
td.reset();
208+
209+
const clock = installClock();
208210
foundation.close();
209211

212+
// Wait till setTimeout callback is executed.
213+
clock.runToFrame();
214+
clock.tick(100);
215+
clock.tick(numbers.DIALOG_ANIMATION_OPEN_TIME_MS);
216+
210217
td.verify(mockAdapter.releaseFocus());
211218
});
212219

0 commit comments

Comments
 (0)