Skip to content

Commit

Permalink
fix(drawer): Destroy list in destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
williamernest committed Aug 29, 2018
1 parent 453b5c5 commit 89ad4f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
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_;

/** @prviate {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

0 comments on commit 89ad4f3

Please sign in to comment.