Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

focus-lock

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

focus-lock - npm Package Compare versions

Comparing version 0.0.6 to 0.1.0

dist/utils/firstFocus.js

19

dist/focusMerge.js

@@ -14,4 +14,12 @@ 'use strict';

var findAutoFocused = function findAutoFocused(node) {
return !!node.autofocus || node.dataset && !!node.dataset.autofocus;
var _firstFocus = require('./utils/firstFocus');
var _firstFocus2 = _interopRequireDefault(_firstFocus);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var findAutoFocused = function findAutoFocused(autoFocusables) {
return function (node) {
return !!node.autofocus || node.dataset && !!node.dataset.autofocus || autoFocusables.indexOf(node) >= 0;
};
};

@@ -38,6 +46,3 @@

if (activeIndex === -1 || lastNodeInside === -1) {
if (autoFocused) {
return innerNodes.indexOf(autoFocused);
}
return 0;
return innerNodes.indexOf(autoFocused.length ? (0, _firstFocus2.default)(autoFocused) : (0, _firstFocus2.default)(innerNodes));
}

@@ -91,3 +96,3 @@ // old focus

var newId = newFocus(innerNodes, outerNodes, activeElement, lastNode, innerNodes.find(findAutoFocused));
var newId = newFocus(innerNodes, outerNodes, activeElement, lastNode, innerNodes.filter(findAutoFocused((0, _DOMutils.parentAutofocusables)(topNode))));

@@ -94,0 +99,0 @@ if (newId === undefined) {

@@ -6,3 +6,3 @@ 'use strict';

});
exports.getTabbableNodes = exports.getCommonParent = exports.notHiddenInput = exports.isVisible = undefined;
exports.parentAutofocusables = exports.getTabbableNodes = exports.getCommonParent = exports.notHiddenInput = exports.isVisible = undefined;

@@ -60,2 +60,6 @@ var _tabOrder = require('./tabOrder');

return (0, _tabOrder.orderByTabIndex)(findFocusable((0, _tabUtils.getFocusables)(topNode)));
};
var parentAutofocusables = exports.parentAutofocusables = function parentAutofocusables(topNode) {
return findFocusable((0, _tabUtils.getParentAutofocusables)(topNode));
};

@@ -6,3 +6,3 @@ 'use strict';

});
exports.getFocusables = undefined;
exports.getParentAutofocusables = exports.getFocusables = undefined;

@@ -15,4 +15,15 @@ var _tabbables = require('./tabbables');

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 getFocusables = exports.getFocusables = function getFocusables(parent) {
return parent.querySelectorAll(_tabbables2.default.join(','));
};
var getParentAutofocusables = exports.getParentAutofocusables = function getParentAutofocusables(parent) {
var parentFocus = parent.querySelectorAll('[data-autofocus-inside]');
return [].concat(_toConsumableArray(parentFocus)).map(function (node) {
return getFocusables(node);
}).reduce(function (acc, nodes) {
return [].concat(_toConsumableArray(acc), _toConsumableArray(nodes));
}, []);
};
{
"name": "focus-lock",
"version": "0.0.6",
"version": "0.1.0",
"description": "DOM trap for a focus",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,6 +0,8 @@

import { orderByTabIndex } from './utils/tabOrder';
import { getCommonParent, getTabbableNodes } from './utils/DOMutils';
import { getFocusables } from './utils/tabUtils';
import {orderByTabIndex} from './utils/tabOrder';
import {getCommonParent, getTabbableNodes, parentAutofocusables} from './utils/DOMutils';
import {getFocusables} from './utils/tabUtils';
import pickFirstFocus from './utils/firstFocus';
const findAutoFocused = node => !!node.autofocus || (node.dataset && !!node.dataset.autofocus);
const findAutoFocused = autoFocusables => node =>
!!node.autofocus || (node.dataset && !!node.dataset.autofocus) || autoFocusables.indexOf(node) >= 0;

@@ -26,6 +28,7 @@ export const newFocus = (innerNodes, outerNodes, activeElement, lastNode, autoFocused) => {

if (activeIndex === -1 || lastNodeInside === -1) {
if (autoFocused) {
return innerNodes.indexOf(autoFocused);
}
return 0;
return innerNodes.indexOf(
autoFocused.length
? pickFirstFocus(autoFocused)
: pickFirstFocus(innerNodes)
);
}

@@ -69,9 +72,9 @@ // old focus

const innerNodes = innerElements.map(({ node }) => node);
const innerNodes = innerElements.map(({node}) => node);
const outerNodes = orderByTabIndex(getFocusables(commonParent)).map(({ node }) => node);
const outerNodes = orderByTabIndex(getFocusables(commonParent)).map(({node}) => node);
const newId = newFocus(
innerNodes, outerNodes,
activeElement, lastNode, innerNodes.find(findAutoFocused),
activeElement, lastNode, innerNodes.filter(findAutoFocused(parentAutofocusables(topNode))),
);

@@ -78,0 +81,0 @@

import { orderByTabIndex } from './tabOrder';
import { getFocusables } from './tabUtils';
import { getFocusables, getParentAutofocusables } from './tabUtils';

@@ -45,3 +45,2 @@ const isElementHidden = computedStyle => (

export const getTabbableNodes = topNode =>

@@ -51,1 +50,4 @@ orderByTabIndex(

);
export const parentAutofocusables = topNode =>
findFocusable(getParentAutofocusables(topNode))
import tabbables from './tabbables';
export const getFocusables = parent => parent.querySelectorAll(tabbables.join(','));
export const getParentAutofocusables = parent => {
const parentFocus = parent.querySelectorAll('[data-autofocus-inside]');
return [...parentFocus]
.map( node => getFocusables(node))
.reduce( (acc,nodes) => [...acc,...nodes],[])
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc