diff --git a/src/DropdownMenu.js b/src/DropdownMenu.js index ecc1b8436c..3a0773425c 100644 --- a/src/DropdownMenu.js +++ b/src/DropdownMenu.js @@ -38,6 +38,10 @@ class DropdownMenu extends React.Component { focusNext() { let { items, activeItemIndex } = this.getItemsAndActiveIndex(); + if (items.length === 0) { + return; + } + if (activeItemIndex === items.length - 1) { items[0].focus(); return; diff --git a/test/DropdownSpec.js b/test/DropdownSpec.js index 24003ca6f5..db1efb64b2 100644 --- a/test/DropdownSpec.js +++ b/test/DropdownSpec.js @@ -186,6 +186,21 @@ describe('Dropdown', function() { buttonNode.getAttribute('aria-expanded').should.equal('false'); }); + it('opens if dropdown contains no focusable menu item', function() { + const instance = ReactTestUtils.renderIntoDocument( + + Toggle + +
  • Some custom nonfocusable content
  • +
    +
    + ); + const node = React.findDOMNode(instance); + const buttonNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'BUTTON')); + ReactTestUtils.Simulate.click(buttonNode); + node.className.should.match(/\bopen\b/); + }); + it('when focused and closed toggles open when the key "down" is pressed', function() { const instance = ReactTestUtils.renderIntoDocument(simpleDropdown); const node = React.findDOMNode(instance);