Skip to content

Commit

Permalink
Merge branch 'master' into fix/drawer/click_target
Browse files Browse the repository at this point in the history
  • Loading branch information
williamernest committed Aug 31, 2018
2 parents 7d88071 + 5dea634 commit c2027a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mdc-menu/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class MDCMenuFoundation extends MDCFoundation {

// Iterate through ancestors until we find the group or get to the list.
while (!isGroup && !this.adapter_.elementContainsClass(parent, MDCListFoundation.cssClasses.ROOT)) {
parent = this.adapter_.getParentElement(listItem);
parent = this.adapter_.getParentElement(parent);
isGroup = this.adapter_.elementContainsClass(parent, cssClasses.MENU_SELECTION_GROUP);
}

Expand Down
22 changes: 22 additions & 0 deletions test/unit/mdc-menu/menu.foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,28 @@ test('handleKeydown space/enter key inside of a list item not inside of the menu
td.verify(mockAdapter.notifySelected(td.matchers.anything()), {times: 0});
});

test('handleKeydown space/enter key inside of a selection group ' +
'with additional markup does not cause loop', () => {
// This test will timeout of there is an endless loop in the selection group logic.
const {foundation, mockAdapter} = setupTest();
const clock = lolex.install();
const parentElement = {};
const event = {key: 'Space', target: {tagName: 'li'}, preventDefault: td.func('preventDefault')};
td.when(mockAdapter.elementContainsClass(event.target, listClasses.LIST_ITEM_CLASS)).thenReturn(true);
td.when(mockAdapter.elementContainsClass(td.matchers.anything(), listClasses.ROOT)).thenReturn(false, true);
td.when(mockAdapter.getElementIndex(event.target)).thenReturn(0);
td.when(mockAdapter.getParentElement(td.matchers.anything())).thenReturn(parentElement, null);
td.when(mockAdapter.elementContainsClass(td.matchers.anything(), cssClasses.MENU_SELECTION_GROUP)).thenReturn(false);

foundation.handleKeydown(event);
event.key = 'Enter';
foundation.handleKeydown(event);
clock.tick(numbers.TRANSITION_CLOSE_DURATION);

td.verify(mockAdapter.closeSurface(), {times: 2});
clock.uninstall();
});

test('handleKeydown space/enter key inside of a selection group with another element selected', () => {
const {foundation, mockAdapter} = setupTest();
const clock = lolex.install();
Expand Down

0 comments on commit c2027a9

Please sign in to comment.