Skip to content

Instantly share code, notes, and snippets.

@AlexKVal
Created April 29, 2015 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexKVal/0347c4306d5a2f789803 to your computer and use it in GitHub Desktop.
Save AlexKVal/0347c4306d5a2f789803 to your computer and use it in GitHub Desktop.
it('should focus dropdown items when pressing cursor up and down keys', function () {
// Have to run this in actual DOM to verify focus
let testContainer = document.createElement('div');
document.body.appendChild(testContainer);
// Create instance as normal, only in DOM
instance = React.render(
<DropdownButton title="Title">
<MenuItem eventKey="1">MenuItem 1 content</MenuItem>
<MenuItem eventKey="2">MenuItem 2 content</MenuItem>
</DropdownButton>
, testContainer);
let items = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'a');
ReactTestUtils.Simulate.click(instance.refs.dropdownButton);
let menu = React.findDOMNode(instance.refs.menu);
ReactTestUtils.Simulate.keyDown(menu, {keyCode: 40});
assert.equal(document.activeElement, items[0].getDOMNode());
ReactTestUtils.Simulate.keyDown(menu, {keyCode: 40});
assert.equal(document.activeElement, items[1].getDOMNode());
ReactTestUtils.Simulate.keyDown(menu, {keyCode: 38});
assert.equal(document.activeElement, items[0].getDOMNode());
// Clean up
React.unmountComponentAtNode(testContainer);
document.body.removeChild(testContainer);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment