Skip to content

Commit

Permalink
Merge pull request react-bootstrap#1225 from jesenko/dropdown-no-menu
Browse files Browse the repository at this point in the history
[fixed] Error on opening dropdown without focusable items
  • Loading branch information
jquense committed Sep 4, 2015
2 parents b9384be + 3a369cc commit c4d7f27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/DropdownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/DropdownSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Dropdown title='custom child' id='dropdown'>
<Dropdown.Toggle>Toggle</Dropdown.Toggle>
<Dropdown.Menu>
<li>Some custom nonfocusable content</li>
</Dropdown.Menu>
</Dropdown>
);
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);
Expand Down

0 comments on commit c4d7f27

Please sign in to comment.