Skip to content

Commit

Permalink
Merge pull request #120 from evoyy/pr/bugfix_empty_tabbable_array
Browse files Browse the repository at this point in the history
[fixed] Handle case when no tabbable element exists
  • Loading branch information
claydiffrient committed Mar 25, 2016
2 parents 06ebde2 + 471ef4c commit 23eee3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/helpers/scopeTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var findTabbable = require('../helpers/tabbable');

module.exports = function(node, event) {
var tabbable = findTabbable(node);
if (!tabbable.length) return;
var finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
var leavingFinalTabbable = (
finalTabbable === document.activeElement ||
Expand Down
8 changes: 8 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ describe('Modal', function () {
});
});

it('handles case when child has no tabbable elements', function() {
var component = renderModal({isOpen: true}, 'hello');
assert.doesNotThrow(function() {
Simulate.keyDown(component.portal.refs.content, {key: "Tab", keyCode: 9, which: 9})
});
unmountModal();
});

it('supports custom className', function() {
var modal = renderModal({isOpen: true, className: 'myClass'});
equal(modal.portal.refs.content.className.contains('myClass'), true);
Expand Down

0 comments on commit 23eee3b

Please sign in to comment.