Skip to content

[fixed] Handle case when no tabbable element exists #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that you forgot to make an assertion in the spec. It just opens the modal, presses tab then closes it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claydiffrient I have updated the spec to use assert.doesNotThrow().

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