focus-lock
Advanced tools
Comparing version 0.6.6 to 0.6.7
@@ -0,1 +1,46 @@ | ||
## [0.6.7](https://github.com/theKashey/focus-lock/compare/v0.6.6...v0.6.7) (2020-04-17) | ||
### Bug Fixes | ||
* better handle jump out conditions. Focus on the active radio and look for tailing guards as well ([421e869](https://github.com/theKashey/focus-lock/commit/421e869)) | ||
## [0.6.6](https://github.com/theKashey/focus-lock/compare/v0.6.5...v0.6.6) (2019-10-17) | ||
### Bug Fixes | ||
* detect document using nodeType, fixes [#11](https://github.com/theKashey/focus-lock/issues/11) ([c03e6bc](https://github.com/theKashey/focus-lock/commit/c03e6bc)) | ||
## [0.6.5](https://github.com/theKashey/focus-lock/compare/v0.6.4...v0.6.5) (2019-06-10) | ||
### Bug Fixes | ||
* dont use array.find, fixes [#9](https://github.com/theKashey/focus-lock/issues/9) ([cbeec63](https://github.com/theKashey/focus-lock/commit/cbeec63)) | ||
## [0.6.4](https://github.com/theKashey/focus-lock/compare/v0.6.3...v0.6.4) (2019-05-28) | ||
### Features | ||
* sidecar for constants ([8a42017](https://github.com/theKashey/focus-lock/commit/8a42017)) | ||
## [0.6.3](https://github.com/theKashey/focus-lock/compare/v0.6.2...v0.6.3) (2019-04-22) | ||
### Bug Fixes | ||
* allow top guard jump ([58237a3](https://github.com/theKashey/focus-lock/commit/58237a3)) | ||
## [0.6.2](https://github.com/theKashey/focus-lock/compare/v0.6.1...v0.6.2) (2019-03-11) | ||
@@ -2,0 +47,0 @@ |
@@ -39,2 +39,3 @@ 'use strict'; | ||
var lastFocus = innerNodes[cnt - 1]; | ||
var isOnGuard = isGuard(activeElement); | ||
@@ -53,2 +54,5 @@ // focus is inside | ||
var returnFirstNode = (0, _firstFocus.pickFocusable)(innerNodes, 0); | ||
var returnLastNode = (0, _firstFocus.pickFocusable)(innerNodes, cnt - 1); | ||
// new focus | ||
@@ -63,6 +67,10 @@ if (activeIndex === -1 || lastNodeInside === -1) { | ||
// first element | ||
if (activeIndex <= firstNodeIndex && isGuard(activeElement) && Math.abs(indexDiff) > 1) { | ||
return 0; | ||
if (activeIndex <= firstNodeIndex && isOnGuard && Math.abs(indexDiff) > 1) { | ||
return returnLastNode; | ||
} | ||
// jump out | ||
// last element | ||
if (activeIndex >= firstNodeIndex && isOnGuard && Math.abs(indexDiff) > 1) { | ||
return returnFirstNode; | ||
} | ||
// jump out, but not on the guard | ||
if (indexDiff && Math.abs(indexDiff) > 1) { | ||
@@ -73,7 +81,7 @@ return lastNodeInside; | ||
if (activeIndex <= firstNodeIndex) { | ||
return cnt - 1; | ||
return returnLastNode; | ||
} | ||
// focus below lock | ||
if (activeIndex > lastNodeIndex) { | ||
return 0; | ||
return returnFirstNode; | ||
} | ||
@@ -80,0 +88,0 @@ // index is inside tab order, but outside Lock |
@@ -27,2 +27,11 @@ 'use strict'; | ||
var pickFocusable = exports.pickFocusable = function pickFocusable(nodes, index) { | ||
if (nodes.length > 1) { | ||
if (isRadio(nodes[index]) && nodes[index].name) { | ||
return nodes.indexOf(findSelectedRadio(nodes[index], nodes)); | ||
} | ||
} | ||
return index; | ||
}; | ||
exports.default = pickFirstFocus; |
import { getCommonParent, getTabbableNodes, getAllTabbableNodes, parentAutofocusables } from './utils/DOMutils'; | ||
import pickFirstFocus from './utils/firstFocus'; | ||
import pickFirstFocus, { pickFocusable } from './utils/firstFocus'; | ||
import getAllAffectedNodes from './utils/all-affected'; | ||
@@ -23,2 +23,3 @@ import { asArray } from './utils/array'; | ||
var lastFocus = innerNodes[cnt - 1]; | ||
var isOnGuard = isGuard(activeElement); | ||
@@ -37,2 +38,5 @@ // focus is inside | ||
var returnFirstNode = pickFocusable(innerNodes, 0); | ||
var returnLastNode = pickFocusable(innerNodes, cnt - 1); | ||
// new focus | ||
@@ -47,6 +51,10 @@ if (activeIndex === -1 || lastNodeInside === -1) { | ||
// first element | ||
if (activeIndex <= firstNodeIndex && isGuard(activeElement) && Math.abs(indexDiff) > 1) { | ||
return 0; | ||
if (activeIndex <= firstNodeIndex && isOnGuard && Math.abs(indexDiff) > 1) { | ||
return returnLastNode; | ||
} | ||
// jump out | ||
// last element | ||
if (activeIndex >= firstNodeIndex && isOnGuard && Math.abs(indexDiff) > 1) { | ||
return returnFirstNode; | ||
} | ||
// jump out, but not on the guard | ||
if (indexDiff && Math.abs(indexDiff) > 1) { | ||
@@ -57,7 +65,7 @@ return lastNodeInside; | ||
if (activeIndex <= firstNodeIndex) { | ||
return cnt - 1; | ||
return returnLastNode; | ||
} | ||
// focus below lock | ||
if (activeIndex > lastNodeIndex) { | ||
return 0; | ||
return returnFirstNode; | ||
} | ||
@@ -64,0 +72,0 @@ // index is inside tab order, but outside Lock |
@@ -22,2 +22,11 @@ var isRadio = function isRadio(node) { | ||
export var pickFocusable = function pickFocusable(nodes, index) { | ||
if (nodes.length > 1) { | ||
if (isRadio(nodes[index]) && nodes[index].name) { | ||
return nodes.indexOf(findSelectedRadio(nodes[index], nodes)); | ||
} | ||
} | ||
return index; | ||
}; | ||
export default pickFirstFocus; |
{ | ||
"name": "focus-lock", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"description": "DOM trap for a focus", | ||
@@ -15,7 +15,7 @@ "main": "dist/cjs/index.js", | ||
"test:pick": "NODE_ENV=cjs mocha --compilers js:babel-core/register -r jsdom-global/register", | ||
"prepublish": "npm run build", | ||
"prepublish": "npm run build && npm run changelog", | ||
"lint": "eslint src tests", | ||
"lint:fix": "eslint src tests --fix", | ||
"size": "yarn size-limit", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0" | ||
}, | ||
@@ -22,0 +22,0 @@ "repository": { |
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
43235
873