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

Commit dffbcc1

Browse files
authored
fix(drawer): Fix restore & release focus order when closing the drawer (#4304)
1 parent 58c3b4d commit dffbcc1

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/mdc-drawer/dismissible/foundation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ class MDCDismissibleDrawerFoundation extends MDCFoundation {
168168

169169
if (this.isClosing()) {
170170
this.adapter_.removeClass(OPEN);
171-
this.adapter_.restoreFocus();
172171
this.closed();
172+
this.adapter_.restoreFocus();
173173
this.adapter_.notifyClose();
174174
} else {
175175
this.adapter_.focusActiveNavigationItem();

packages/mdc-drawer/modal/foundation.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* THE SOFTWARE.
2222
*/
2323

24-
import MDCDrawerAdapter from '../adapter';
2524
import MDCDismissibleDrawerFoundation from '../dismissible/foundation';
2625

2726
/**

test/unit/mdc-drawer/dismissible.foundation.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,18 @@ test('#handleTransitionEnd doesn\'t do anything if event is emitted with a non-e
273273
td.verify(mockAdapter.notifyOpen(), {times: 0});
274274
td.verify(mockAdapter.notifyClose(), {times: 0});
275275
});
276+
277+
test('#handleTransitionEnd calls .closed() before restoring the focus.', () => {
278+
const {foundation, mockAdapter} = setupTest();
279+
foundation.closed = td.function();
280+
281+
const mockEventTarget = bel`<div class="foo">bar</div>`;
282+
td.when(mockAdapter.elementHasClass(mockEventTarget, cssClasses.ROOT)).thenReturn(true);
283+
td.when(mockAdapter.hasClass(cssClasses.CLOSING)).thenReturn(true);
284+
const executionOrder = [];
285+
td.when(foundation.closed()).thenDo(() => executionOrder.push('closed'));
286+
td.when(mockAdapter.restoreFocus()).thenDo(() => executionOrder.push('restoreFocus'));
287+
foundation.handleTransitionEnd({target: mockEventTarget});
288+
289+
assert.deepEqual(executionOrder, ['closed', 'restoreFocus']);
290+
});

0 commit comments

Comments
 (0)