focus-trap
Advanced tools
Comparing version 0.3.0 to 0.3.1
20
index.js
@@ -23,11 +23,19 @@ var tabbable = require('tabbable'); | ||
var focusNode = (function() { | ||
if (!config.initialFocus) return tabbableNodes[0]; | ||
var node; | ||
if (!config.initialFocus) { | ||
node = tabbableNodes[0]; | ||
if (!node) { | ||
throw new Error('You can\'t have a focus-trap without at least one focusable element'); | ||
} | ||
} | ||
if (typeof config.initialFocus === 'string') { | ||
return document.querySelector(config.initialFocus); | ||
node = document.querySelector(config.initialFocus); | ||
} else { | ||
node = config.initialFocus; | ||
} | ||
return config.initialFocus; | ||
if (!node) { | ||
throw new Error('The `initialFocus` selector you passed refers to no known node'); | ||
} | ||
return node; | ||
}()); | ||
if (!focusNode) { | ||
throw new Error('You can\'t have a focus-trap without at least one focusable element'); | ||
} | ||
focusNode.focus(); | ||
@@ -34,0 +42,0 @@ |
{ | ||
"name": "focus-trap", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Trap focus within a DOM node.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9236
94