Skip to content

Commit

Permalink
Merge af43884 into 0cb504c
Browse files Browse the repository at this point in the history
  • Loading branch information
adam187 committed Jul 29, 2017
2 parents 0cb504c + af43884 commit a452427
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,17 @@ class Menu extends Component {
return;
}

const {focusIndex} = this.state;
if (focusIndex < 0) {
return;
}

const filteredChildren = this.getFilteredChildren(this.props.children);
const focusedItem = filteredChildren[focusIndex];
if (focusedItem.props.menuItems && focusedItem.props.menuItems.length > 0) {
return;
}

this.setFocusIndex(event, -1, false);
};

Expand Down
23 changes: 23 additions & 0 deletions src/Menu/Menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,27 @@ describe('<Menu />', () => {
assert.deepEqual(wrapper.state().value, ['item2', 'item3']);
});
});

describe('Nested menu', () => {
it('should ignore loosing focus on click away for item with menu items', () => {
const menuItems = [<MenuItem />, <MenuItem />];

const wrapper = mountWithContext(
<Menu className="menu">
<MenuItem className="item1" />
<MenuItem className="item2" menuItems={menuItems} />
</Menu>
);

wrapper.find('.item1').simulate('touchTap');
assert.strictEqual(wrapper.state('focusIndex'), 0);
document.body.dispatchEvent(new window.Event('mouseup', {bubbles: true}));
assert.strictEqual(wrapper.state('focusIndex'), -1);

wrapper.find('.item2').simulate('touchTap');
assert.strictEqual(wrapper.state('focusIndex'), 1);
document.body.dispatchEvent(new window.Event('mouseup', {bubbles: true}));
assert.strictEqual(wrapper.state('focusIndex'), 1);
});
});
});

0 comments on commit a452427

Please sign in to comment.