From 471ef4cc40a305fc3abe3ae8f4e26382fc9d82e3 Mon Sep 17 00:00:00 2001 From: evoyy Date: Tue, 26 Jan 2016 06:32:52 +0000 Subject: [PATCH] Handle case when no tabbable element exists --- lib/helpers/scopeTab.js | 1 + specs/Modal.spec.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/helpers/scopeTab.js b/lib/helpers/scopeTab.js index 737352b6..5ba664fb 100644 --- a/lib/helpers/scopeTab.js +++ b/lib/helpers/scopeTab.js @@ -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 || diff --git a/specs/Modal.spec.js b/specs/Modal.spec.js index e0052815..7a4c44c9 100644 --- a/specs/Modal.spec.js +++ b/specs/Modal.spec.js @@ -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);