focus-lock
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.newFocus = undefined; | ||
exports.getFocusabledIn = exports.newFocus = undefined; | ||
@@ -82,8 +82,8 @@ var _DOMutils = require('./utils/DOMutils'); | ||
var topCommon = null; | ||
leftEntries.forEach(function (entry) { | ||
topCommon = (0, _DOMutils.getCommonParent)(topCommon || entry, entry); | ||
rightEntries.forEach(function (subEntry) { | ||
leftEntries.filter(Boolean).forEach(function (entry) { | ||
topCommon = (0, _DOMutils.getCommonParent)(topCommon || entry, entry) || topCommon; | ||
rightEntries.filter(Boolean).forEach(function (subEntry) { | ||
var common = (0, _DOMutils.getCommonParent)(activeElement, subEntry); | ||
if (common) { | ||
if (common.contains(topCommon)) { | ||
if (!topCommon || common.contains(topCommon)) { | ||
topCommon = common; | ||
@@ -109,2 +109,35 @@ } else { | ||
var reorderNodes = function reorderNodes(srcNodes, dstNodes) { | ||
return srcNodes.map(function (dnode) { | ||
return dstNodes.find(function (_ref) { | ||
var node = _ref.node; | ||
return dnode === node; | ||
}); | ||
}).filter(Boolean); | ||
}; | ||
var getFocusabledIn = exports.getFocusabledIn = function getFocusabledIn(topNode) { | ||
var entries = (0, _allAffected2.default)(topNode).filter(notAGuard); | ||
var commonParent = getTopCommonParent(topNode, topNode, entries); | ||
var outerNodes = (0, _DOMutils.getTabbableNodes)([commonParent], true); | ||
var innerElements = (0, _DOMutils.getTabbableNodes)(entries).filter(function (_ref2) { | ||
var node = _ref2.node; | ||
return notAGuard(node); | ||
}).map(function (_ref3) { | ||
var node = _ref3.node; | ||
return node; | ||
}); | ||
return outerNodes.map(function (_ref4) { | ||
var node = _ref4.node, | ||
index = _ref4.index; | ||
return { | ||
node: node, | ||
index: index, | ||
lockItem: innerElements.indexOf(node) >= 0, | ||
guard: !notAGuard(node) | ||
}; | ||
}); | ||
}; | ||
var getFocusMerge = function getFocusMerge(topNode, lastNode) { | ||
@@ -116,4 +149,4 @@ var activeElement = document && document.activeElement; | ||
var innerElements = (0, _DOMutils.getTabbableNodes)(entries).filter(function (_ref) { | ||
var node = _ref.node; | ||
var innerElements = (0, _DOMutils.getTabbableNodes)(entries).filter(function (_ref5) { | ||
var node = _ref5.node; | ||
return notAGuard(node); | ||
@@ -123,4 +156,4 @@ }); | ||
if (!innerElements[0]) { | ||
innerElements = (0, _DOMutils.getAllTabbableNodes)(entries).filter(function (_ref2) { | ||
var node = _ref2.node; | ||
innerElements = (0, _DOMutils.getAllTabbableNodes)(entries).filter(function (_ref6) { | ||
var node = _ref6.node; | ||
return notAGuard(node); | ||
@@ -133,9 +166,9 @@ }); | ||
var innerNodes = innerElements.map(function (_ref3) { | ||
var node = _ref3.node; | ||
var outerNodes = (0, _DOMutils.getTabbableNodes)([commonParent]).map(function (_ref7) { | ||
var node = _ref7.node; | ||
return node; | ||
}); | ||
var outerNodes = (0, _DOMutils.getTabbableNodes)([commonParent]).map(function (_ref4) { | ||
var node = _ref4.node; | ||
var orderedInnerElements = reorderNodes(outerNodes, innerElements); | ||
var innerNodes = orderedInnerElements.map(function (_ref8) { | ||
var node = _ref8.node; | ||
return node; | ||
@@ -149,5 +182,5 @@ }); | ||
} | ||
return innerElements[newId]; | ||
return orderedInnerElements[newId]; | ||
}; | ||
exports.default = getFocusMerge; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.getAllAffectedNodes = exports.constants = exports.focusMerge = exports.focusIsHidden = exports.focusInside = exports.tabHook = undefined; | ||
exports.getAllAffectedNodes = exports.constants = exports.getFocusabledIn = exports.focusMerge = exports.focusIsHidden = exports.focusInside = exports.tabHook = undefined; | ||
@@ -45,4 +45,5 @@ var _tabHook = require('./tabHook'); | ||
exports.focusMerge = _focusMerge2.default; | ||
exports.getFocusabledIn = _focusMerge.getFocusabledIn; | ||
exports.constants = constants; | ||
exports.getAllAffectedNodes = _allAffected2.default; | ||
exports.default = _setFocus2.default; |
@@ -45,3 +45,3 @@ 'use strict'; | ||
var nodes = (0, _array.asArray)(node); | ||
return nodes.reduce(function (acc, currentNode) { | ||
return nodes.filter(Boolean).reduce(function (acc, currentNode) { | ||
var group = currentNode.getAttribute(_constants.FOCUS_GROUP); | ||
@@ -48,0 +48,0 @@ acc.push.apply(acc, _toConsumableArray(group ? filterNested((0, _array.toArray)(getTopParent(currentNode).querySelectorAll('[' + _constants.FOCUS_GROUP + '="' + group + '"]:not([' + _constants.FOCUS_DISABLED + '="disabled"])'))) : [currentNode])); |
@@ -60,4 +60,4 @@ 'use strict'; | ||
var getTabbableNodes = exports.getTabbableNodes = function getTabbableNodes(topNodes) { | ||
return (0, _tabOrder.orderByTabIndex)(filterFocusable((0, _tabUtils.getFocusables)(topNodes)), true); | ||
var getTabbableNodes = exports.getTabbableNodes = function getTabbableNodes(topNodes, withGuards) { | ||
return (0, _tabOrder.orderByTabIndex)(filterFocusable((0, _tabUtils.getFocusables)(topNodes, withGuards)), true); | ||
}; | ||
@@ -64,0 +64,0 @@ |
@@ -27,3 +27,3 @@ 'use strict'; | ||
index: index, | ||
tabIndex: node.tabIndex | ||
tabIndex: node.tabIndex === -1 ? (node.dataset || {}).focusGuard ? 0 : -1 : node.tabIndex | ||
}; | ||
@@ -30,0 +30,0 @@ }).filter(function (data) { |
@@ -18,5 +18,14 @@ 'use strict'; | ||
var getFocusables = exports.getFocusables = function getFocusables(parents) { | ||
var queryTabbables = _tabbables2.default.join(','); | ||
var queryGuardTabbables = queryTabbables + ', [data-focus-guard]'; | ||
var getFocusables = exports.getFocusables = function getFocusables(parents, withGuards) { | ||
return parents.reduce(function (acc, parent) { | ||
return acc.concat((0, _array.toArray)(parent.querySelectorAll(_tabbables2.default.join(',')))); | ||
return acc.concat( | ||
// add all tabbables inside | ||
(0, _array.toArray)(parent.querySelectorAll(withGuards ? queryGuardTabbables : queryTabbables)), | ||
// add if node is tabble itself | ||
parent.parentNode ? (0, _array.toArray)(parent.parentNode.querySelectorAll(_tabbables2.default.join(','))).filter(function (node) { | ||
return node === parent; | ||
}) : []); | ||
}, []); | ||
@@ -23,0 +32,0 @@ }; |
@@ -65,8 +65,8 @@ import { getCommonParent, getTabbableNodes, getAllTabbableNodes, parentAutofocusables } from './utils/DOMutils'; | ||
var topCommon = null; | ||
leftEntries.forEach(function (entry) { | ||
topCommon = getCommonParent(topCommon || entry, entry); | ||
rightEntries.forEach(function (subEntry) { | ||
leftEntries.filter(Boolean).forEach(function (entry) { | ||
topCommon = getCommonParent(topCommon || entry, entry) || topCommon; | ||
rightEntries.filter(Boolean).forEach(function (subEntry) { | ||
var common = getCommonParent(activeElement, subEntry); | ||
if (common) { | ||
if (common.contains(topCommon)) { | ||
if (!topCommon || common.contains(topCommon)) { | ||
topCommon = common; | ||
@@ -92,2 +92,35 @@ } else { | ||
var reorderNodes = function reorderNodes(srcNodes, dstNodes) { | ||
return srcNodes.map(function (dnode) { | ||
return dstNodes.find(function (_ref) { | ||
var node = _ref.node; | ||
return dnode === node; | ||
}); | ||
}).filter(Boolean); | ||
}; | ||
export var getFocusabledIn = function getFocusabledIn(topNode) { | ||
var entries = getAllAffectedNodes(topNode).filter(notAGuard); | ||
var commonParent = getTopCommonParent(topNode, topNode, entries); | ||
var outerNodes = getTabbableNodes([commonParent], true); | ||
var innerElements = getTabbableNodes(entries).filter(function (_ref2) { | ||
var node = _ref2.node; | ||
return notAGuard(node); | ||
}).map(function (_ref3) { | ||
var node = _ref3.node; | ||
return node; | ||
}); | ||
return outerNodes.map(function (_ref4) { | ||
var node = _ref4.node, | ||
index = _ref4.index; | ||
return { | ||
node: node, | ||
index: index, | ||
lockItem: innerElements.indexOf(node) >= 0, | ||
guard: !notAGuard(node) | ||
}; | ||
}); | ||
}; | ||
var getFocusMerge = function getFocusMerge(topNode, lastNode) { | ||
@@ -99,4 +132,4 @@ var activeElement = document && document.activeElement; | ||
var innerElements = getTabbableNodes(entries).filter(function (_ref) { | ||
var node = _ref.node; | ||
var innerElements = getTabbableNodes(entries).filter(function (_ref5) { | ||
var node = _ref5.node; | ||
return notAGuard(node); | ||
@@ -106,4 +139,4 @@ }); | ||
if (!innerElements[0]) { | ||
innerElements = getAllTabbableNodes(entries).filter(function (_ref2) { | ||
var node = _ref2.node; | ||
innerElements = getAllTabbableNodes(entries).filter(function (_ref6) { | ||
var node = _ref6.node; | ||
return notAGuard(node); | ||
@@ -116,9 +149,9 @@ }); | ||
var innerNodes = innerElements.map(function (_ref3) { | ||
var node = _ref3.node; | ||
var outerNodes = getTabbableNodes([commonParent]).map(function (_ref7) { | ||
var node = _ref7.node; | ||
return node; | ||
}); | ||
var outerNodes = getTabbableNodes([commonParent]).map(function (_ref4) { | ||
var node = _ref4.node; | ||
var orderedInnerElements = reorderNodes(outerNodes, innerElements); | ||
var innerNodes = orderedInnerElements.map(function (_ref8) { | ||
var node = _ref8.node; | ||
return node; | ||
@@ -132,5 +165,5 @@ }); | ||
} | ||
return innerElements[newId]; | ||
return orderedInnerElements[newId]; | ||
}; | ||
export default getFocusMerge; |
import tabHook from './tabHook'; | ||
import focusMerge from './focusMerge'; | ||
import focusMerge, { getFocusabledIn } from './focusMerge'; | ||
import focusInside from './focusInside'; | ||
@@ -9,4 +9,4 @@ import focusIsHidden from './focusIsHidden'; | ||
export { tabHook, focusInside, focusIsHidden, focusMerge, constants, getAllAffectedNodes }; | ||
export { tabHook, focusInside, focusIsHidden, focusMerge, getFocusabledIn, constants, getAllAffectedNodes }; | ||
export default setFocus; |
@@ -36,3 +36,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var nodes = asArray(node); | ||
return nodes.reduce(function (acc, currentNode) { | ||
return nodes.filter(Boolean).reduce(function (acc, currentNode) { | ||
var group = currentNode.getAttribute(FOCUS_GROUP); | ||
@@ -39,0 +39,0 @@ acc.push.apply(acc, group ? filterNested(toArray(getTopParent(currentNode).querySelectorAll('[' + FOCUS_GROUP + '="' + group + '"]:not([' + FOCUS_DISABLED + '="disabled"])'))) : [currentNode]); |
@@ -51,4 +51,4 @@ import { orderByTabIndex } from './tabOrder'; | ||
export var getTabbableNodes = function getTabbableNodes(topNodes) { | ||
return orderByTabIndex(filterFocusable(getFocusables(topNodes)), true); | ||
export var getTabbableNodes = function getTabbableNodes(topNodes, withGuards) { | ||
return orderByTabIndex(filterFocusable(getFocusables(topNodes, withGuards)), true); | ||
}; | ||
@@ -55,0 +55,0 @@ |
@@ -20,3 +20,3 @@ import { toArray } from './array'; | ||
index: index, | ||
tabIndex: node.tabIndex | ||
tabIndex: node.tabIndex === -1 ? (node.dataset || {}).focusGuard ? 0 : -1 : node.tabIndex | ||
}; | ||
@@ -23,0 +23,0 @@ }).filter(function (data) { |
@@ -5,5 +5,14 @@ import tabbables from './tabbables'; | ||
export var getFocusables = function getFocusables(parents) { | ||
var queryTabbables = tabbables.join(','); | ||
var queryGuardTabbables = queryTabbables + ', [data-focus-guard]'; | ||
export var getFocusables = function getFocusables(parents, withGuards) { | ||
return parents.reduce(function (acc, parent) { | ||
return acc.concat(toArray(parent.querySelectorAll(tabbables.join(',')))); | ||
return acc.concat( | ||
// add all tabbables inside | ||
toArray(parent.querySelectorAll(withGuards ? queryGuardTabbables : queryTabbables)), | ||
// add if node is tabble itself | ||
parent.parentNode ? toArray(parent.parentNode.querySelectorAll(tabbables.join(','))).filter(function (node) { | ||
return node === parent; | ||
}) : []); | ||
}, []); | ||
@@ -10,0 +19,0 @@ }; |
{ | ||
"name": "focus-lock", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "DOM trap for a focus", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/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
334850
823