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

fix(drawer): Destroy list in destroy method #3474

Merged
merged 3 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/mdc-drawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class MDCDrawer extends MDCComponent {

/** @private {?Function} */
this.handleScrimClick_;

/** @private {?MDCList} */
this.list_;
}

/**
Expand Down Expand Up @@ -92,10 +95,13 @@ class MDCDrawer extends MDCComponent {
}

initialize(
focusTrapFactory = createFocusTrap) {
focusTrapFactory = createFocusTrap,
listFactory = (el) => new MDCList(el)) {
const listEl = /** @type {!Element} */ (this.root_.querySelector(`.${MDCListFoundation.cssClasses.ROOT}`));
const list = MDCList.attachTo(listEl);
list.wrapFocus = true;
if (listEl) {
this.list_ = listFactory(listEl);
this.list_.wrapFocus = true;
}
this.focusTrapFactory_ = focusTrapFactory;
}

Expand All @@ -121,6 +127,10 @@ class MDCDrawer extends MDCComponent {
this.root_.removeEventListener('keydown', this.handleKeydown_);
this.root_.removeEventListener('transitionend', this.handleTransitionEnd_);

if (this.list_) {
this.list_.destroy();
}

const {MODAL} = MDCDismissibleDrawerFoundation.cssClasses;
if (this.root_.classList.contains(MODAL)) {
this.scrim_.removeEventListener('click', /** @type {!Function} */ (this.handleScrimClick_));
Expand Down
16 changes: 14 additions & 2 deletions test/unit/mdc-drawer/mdc-drawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ function setupTestWithMocks(variantClass = cssClasses.DISMISSIBLE) {
activate: () => {},
deactivate: () => {},
});
const component = new MDCDrawer(drawer, mockFoundation, () => mockFocusTrapInstance);
return {root, drawer, component, mockFoundation, mockFocusTrapInstance};
const mockList = td.object({
wrapFocus: () => {},
destroy: () => {},
});

const component = new MDCDrawer(drawer, mockFoundation, () => mockFocusTrapInstance, () => mockList);
return {root, drawer, component, mockFoundation, mockFocusTrapInstance, mockList};
}

suite('MDCDrawer');
Expand Down Expand Up @@ -134,6 +139,13 @@ test('#destroy removes transitionend event listener', () => {
td.verify(mockFoundation.handleTransitionEnd(td.matchers.isA(Object)), {times: 0});
});

test('#destroy calls destroy on list', () => {
const {component, mockList} = setupTestWithMocks();
component.destroy();

td.verify(mockList.destroy(), {times: 1});
});

test('adapter#addClass adds class to drawer', () => {
const {component, drawer} = setupTest();
component.getDefaultFoundation().adapter_.addClass('test-class');
Expand Down