focus-lock
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -7,12 +7,26 @@ 'use strict'; | ||
var _allAffected = require('./utils/all-affected'); | ||
var _allAffected2 = _interopRequireDefault(_allAffected); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var focusInFrame = function focusInFrame(frame) { | ||
return frame.contentWindow.document.hasFocus(); | ||
}; | ||
var focusInsideIframe = function focusInsideIframe(topNode) { | ||
return !![].concat(_toConsumableArray(topNode.querySelectorAll('iframe'))).find(function (frame) { | ||
return frame.contentWindow.document.hasFocus(); | ||
}); | ||
return (0, _allAffected2.default)(topNode).reduce(function (result, node) { | ||
return result || !![].concat(_toConsumableArray(node.querySelectorAll('iframe'))).find(focusInFrame); | ||
}, false); | ||
}; | ||
exports.default = function (topNode) { | ||
return topNode.querySelector('*:focus') || focusInsideIframe(topNode); | ||
}; | ||
var focusInside = function focusInside(topNode) { | ||
return (0, _allAffected2.default)(topNode).reduce(function (result, node) { | ||
return result || node.querySelector('*:focus') || focusInsideIframe(topNode); | ||
}, false); | ||
}; | ||
exports.default = focusInside; |
@@ -18,4 +18,10 @@ 'use strict'; | ||
var _allAffected = require('./utils/all-affected'); | ||
var _allAffected2 = _interopRequireDefault(_allAffected); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var findAutoFocused = function findAutoFocused(autoFocusables) { | ||
@@ -75,8 +81,30 @@ return function (node) { | ||
var getTopCommonParent = function getTopCommonParent(activeElement, entry, entries) { | ||
var topCommon = entry; | ||
entries.forEach(function (subEntry) { | ||
var common = (0, _DOMutils.getCommonParent)(activeElement, subEntry); | ||
if (common) { | ||
if (common.contains(topCommon)) { | ||
topCommon = common; | ||
} else { | ||
topCommon = (0, _DOMutils.getCommonParent)(common, topCommon); | ||
} | ||
} | ||
}); | ||
return topCommon; | ||
}; | ||
var allParentAutofocusables = function allParentAutofocusables(entries) { | ||
return entries.reduce(function (acc, node) { | ||
return [].concat(_toConsumableArray(acc), _toConsumableArray((0, _DOMutils.parentAutofocusables)(node))); | ||
}, []); | ||
}; | ||
var getFocusMerge = function getFocusMerge(topNode, lastNode) { | ||
var activeElement = document.activeElement; | ||
var entries = (0, _allAffected2.default)(topNode); | ||
var commonParent = (0, _DOMutils.getCommonParent)(activeElement || topNode, topNode) || topNode; | ||
var commonParent = getTopCommonParent(activeElement || topNode, topNode, entries); | ||
var innerElements = (0, _DOMutils.getTabbableNodes)(topNode); | ||
var innerElements = (0, _DOMutils.getTabbableNodes)(entries); | ||
if (!innerElements[0]) { | ||
@@ -91,3 +119,3 @@ return undefined; | ||
var outerNodes = (0, _tabOrder.orderByTabIndex)((0, _tabUtils.getFocusables)(commonParent)).map(function (_ref2) { | ||
var outerNodes = (0, _tabOrder.orderByTabIndex)((0, _tabUtils.getFocusables)([commonParent])).map(function (_ref2) { | ||
var node = _ref2.node; | ||
@@ -97,3 +125,3 @@ return node; | ||
var newId = newFocus(innerNodes, outerNodes, activeElement, lastNode, innerNodes.filter(findAutoFocused((0, _DOMutils.parentAutofocusables)(topNode)))); | ||
var newId = newFocus(innerNodes, outerNodes, activeElement, lastNode, innerNodes.filter(findAutoFocused(allParentAutofocusables(entries)))); | ||
@@ -100,0 +128,0 @@ if (newId === undefined) { |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.focusMerge = exports.focusInside = exports.tabHook = undefined; | ||
exports.getAllAffectedNodes = exports.constants = exports.focusMerge = exports.focusInside = exports.tabHook = undefined; | ||
@@ -25,2 +25,12 @@ var _tabHook = require('./tabHook'); | ||
var _constants = require('./constants'); | ||
var constants = _interopRequireWildcard(_constants); | ||
var _allAffected = require('./utils/all-affected'); | ||
var _allAffected2 = _interopRequireDefault(_allAffected); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -31,2 +41,4 @@ | ||
exports.focusMerge = _focusMerge2.default; | ||
exports.constants = constants; | ||
exports.getAllAffectedNodes = _allAffected2.default; | ||
exports.default = _setFocus2.default; |
@@ -57,4 +57,4 @@ 'use strict'; | ||
var getTabbableNodes = exports.getTabbableNodes = function getTabbableNodes(topNode) { | ||
return (0, _tabOrder.orderByTabIndex)(findFocusable((0, _tabUtils.getFocusables)(topNode))); | ||
var getTabbableNodes = exports.getTabbableNodes = function getTabbableNodes(topNodes) { | ||
return (0, _tabOrder.orderByTabIndex)(findFocusable((0, _tabUtils.getFocusables)(topNodes))); | ||
}; | ||
@@ -61,0 +61,0 @@ |
@@ -6,12 +6,2 @@ 'use strict'; | ||
}); | ||
var findFormParent = function findFormParent(startNode) { | ||
var node = startNode; | ||
while (node = node.parentNode) { | ||
if (node.tagName === 'FORM') { | ||
return node; | ||
} | ||
} | ||
return null; | ||
}; | ||
var isRadio = function isRadio(node) { | ||
@@ -18,0 +8,0 @@ return node.tagName === 'INPUT' && node.type === 'radio'; |
@@ -16,4 +16,6 @@ 'use strict'; | ||
var getFocusables = exports.getFocusables = function getFocusables(parent) { | ||
return parent.querySelectorAll(_tabbables2.default.join(',')); | ||
var getFocusables = exports.getFocusables = function getFocusables(parents) { | ||
return parents.reduce(function (acc, parent) { | ||
return [].concat(_toConsumableArray(acc), _toConsumableArray(parent.querySelectorAll(_tabbables2.default.join(',')))); | ||
}, []); | ||
}; | ||
@@ -20,0 +22,0 @@ |
{ | ||
"name": "focus-lock", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "DOM trap for a focus", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
135133
18
377