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

@zendeskgarden/container-focusjail

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zendeskgarden/container-focusjail - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

118

dist/index.cjs.js

@@ -22,30 +22,2 @@ /**

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function ownerDocument(node) {

@@ -68,19 +40,15 @@ return node && node.ownerDocument || document;

var _excluded$1 = ["onKeyDown"];
var useFocusJail = function useFocusJail(_temp) {
var _ref = _temp === void 0 ? {
const useFocusJail = function (_temp) {
let {
focusOnMount = true,
restoreFocus = true,
environment,
focusElem,
containerRef
} = _temp === void 0 ? {
containerRef: React.createRef()
} : _temp,
_ref$focusOnMount = _ref.focusOnMount,
focusOnMount = _ref$focusOnMount === void 0 ? true : _ref$focusOnMount,
_ref$restoreFocus = _ref.restoreFocus,
restoreFocus = _ref$restoreFocus === void 0 ? true : _ref$restoreFocus,
environment = _ref.environment,
focusElem = _ref.focusElem,
containerRef = _ref.containerRef;
var restoreFocusElement = React.useRef(null);
var _useState = React.useState(containerRef.current),
currentRef = _useState[0],
setCurrentRef = _useState[1];
React.useEffect(function () {
} : _temp;
const restoreFocusElement = React.useRef(null);
const [currentRef, setCurrentRef] = React.useState(containerRef.current);
React.useEffect(() => {
if (containerRef.current !== currentRef) {

@@ -90,3 +58,3 @@ setCurrentRef(containerRef.current);

});
var focusElement = React.useCallback(function (element) {
const focusElement = React.useCallback(element => {
if (focusElem) {

@@ -98,3 +66,3 @@ focusElem(element);

}, [focusElem]);
var validateContainerRef = function validateContainerRef() {
const validateContainerRef = () => {
if (!currentRef) {

@@ -104,10 +72,10 @@ throw new Error('Accessibility Error: You must apply the ref prop to your containing element.');

};
var getInitialFocusNode = function getInitialFocusNode() {
var doc = environment ? environment : document;
var activeElem = activeElement(doc);
var containerElem = currentRef;
const getInitialFocusNode = () => {
const doc = environment ? environment : document;
const activeElem = activeElement(doc);
const containerElem = currentRef;
return containerElem.contains(activeElem) ? activeElem : containerElem;
};
var getTabbableNodes = function getTabbableNodes() {
var elements = tabbable.tabbable(currentRef);
const getTabbableNodes = () => {
const elements = tabbable.tabbable(currentRef);
return {

@@ -118,8 +86,9 @@ firstItem: elements[0] || getInitialFocusNode(),

};
var getContainerProps = function getContainerProps(_temp2) {
var _ref2 = _temp2 === void 0 ? {} : _temp2,
onKeyDown = _ref2.onKeyDown,
other = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
return _extends({
onKeyDown: containerUtilities.composeEventHandlers(onKeyDown, function (event) {
const getContainerProps = function (_temp2) {
let {
onKeyDown,
...other
} = _temp2 === void 0 ? {} : _temp2;
return {
onKeyDown: containerUtilities.composeEventHandlers(onKeyDown, event => {
if (event.key !== containerUtilities.KEYS.TAB) {

@@ -129,3 +98,3 @@ return;

validateContainerRef();
var tabbableNodes = getTabbableNodes();
const tabbableNodes = getTabbableNodes();
if (event.shiftKey && (event.target === tabbableNodes.firstItem || event.target === currentRef)) {

@@ -141,7 +110,8 @@ focusElement(tabbableNodes.lastItem);

'data-garden-container-id': 'containers.focusjail',
'data-garden-container-version': '2.0.0'
}, other);
'data-garden-container-version': '2.0.1',
...other
};
};
React.useEffect(function () {
var doc = environment || document;
React.useEffect(() => {
const doc = environment || document;
restoreFocusElement.current = activeElement(doc);

@@ -151,5 +121,5 @@ if (focusOnMount) {

}
return function () {
var isBodyInactive = restoreFocusElement.current !== doc.body;
var hasActiveElement = restoreFocusElement.current !== null;
return () => {
const isBodyInactive = restoreFocusElement.current !== doc.body;
const hasActiveElement = restoreFocusElement.current !== null;
if (isBodyInactive && hasActiveElement && restoreFocus) {

@@ -161,13 +131,13 @@ focusElement(restoreFocusElement.current);

return {
getContainerProps: getContainerProps,
focusElement: focusElement
getContainerProps,
focusElement
};
};
var _excluded = ["children", "render"];
var FocusJailContainer = function FocusJailContainer(_ref) {
var children = _ref.children,
_ref$render = _ref.render,
render = _ref$render === void 0 ? children : _ref$render,
options = _objectWithoutPropertiesLoose(_ref, _excluded);
const FocusJailContainer = _ref => {
let {
children,
render = children,
...options
} = _ref;
return React__default["default"].createElement(React__default["default"].Fragment, null, render(useFocusJail(options)));

@@ -174,0 +144,0 @@ };

@@ -13,30 +13,2 @@ /**

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function ownerDocument(node) {

@@ -59,19 +31,15 @@ return node && node.ownerDocument || document;

var _excluded$1 = ["onKeyDown"];
var useFocusJail = function useFocusJail(_temp) {
var _ref = _temp === void 0 ? {
const useFocusJail = function (_temp) {
let {
focusOnMount = true,
restoreFocus = true,
environment,
focusElem,
containerRef
} = _temp === void 0 ? {
containerRef: createRef()
} : _temp,
_ref$focusOnMount = _ref.focusOnMount,
focusOnMount = _ref$focusOnMount === void 0 ? true : _ref$focusOnMount,
_ref$restoreFocus = _ref.restoreFocus,
restoreFocus = _ref$restoreFocus === void 0 ? true : _ref$restoreFocus,
environment = _ref.environment,
focusElem = _ref.focusElem,
containerRef = _ref.containerRef;
var restoreFocusElement = useRef(null);
var _useState = useState(containerRef.current),
currentRef = _useState[0],
setCurrentRef = _useState[1];
useEffect(function () {
} : _temp;
const restoreFocusElement = useRef(null);
const [currentRef, setCurrentRef] = useState(containerRef.current);
useEffect(() => {
if (containerRef.current !== currentRef) {

@@ -81,3 +49,3 @@ setCurrentRef(containerRef.current);

});
var focusElement = useCallback(function (element) {
const focusElement = useCallback(element => {
if (focusElem) {

@@ -89,3 +57,3 @@ focusElem(element);

}, [focusElem]);
var validateContainerRef = function validateContainerRef() {
const validateContainerRef = () => {
if (!currentRef) {

@@ -95,10 +63,10 @@ throw new Error('Accessibility Error: You must apply the ref prop to your containing element.');

};
var getInitialFocusNode = function getInitialFocusNode() {
var doc = environment ? environment : document;
var activeElem = activeElement(doc);
var containerElem = currentRef;
const getInitialFocusNode = () => {
const doc = environment ? environment : document;
const activeElem = activeElement(doc);
const containerElem = currentRef;
return containerElem.contains(activeElem) ? activeElem : containerElem;
};
var getTabbableNodes = function getTabbableNodes() {
var elements = tabbable(currentRef);
const getTabbableNodes = () => {
const elements = tabbable(currentRef);
return {

@@ -109,8 +77,9 @@ firstItem: elements[0] || getInitialFocusNode(),

};
var getContainerProps = function getContainerProps(_temp2) {
var _ref2 = _temp2 === void 0 ? {} : _temp2,
onKeyDown = _ref2.onKeyDown,
other = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
return _extends({
onKeyDown: composeEventHandlers(onKeyDown, function (event) {
const getContainerProps = function (_temp2) {
let {
onKeyDown,
...other
} = _temp2 === void 0 ? {} : _temp2;
return {
onKeyDown: composeEventHandlers(onKeyDown, event => {
if (event.key !== KEYS.TAB) {

@@ -120,3 +89,3 @@ return;

validateContainerRef();
var tabbableNodes = getTabbableNodes();
const tabbableNodes = getTabbableNodes();
if (event.shiftKey && (event.target === tabbableNodes.firstItem || event.target === currentRef)) {

@@ -132,7 +101,8 @@ focusElement(tabbableNodes.lastItem);

'data-garden-container-id': 'containers.focusjail',
'data-garden-container-version': '2.0.0'
}, other);
'data-garden-container-version': '2.0.1',
...other
};
};
useEffect(function () {
var doc = environment || document;
useEffect(() => {
const doc = environment || document;
restoreFocusElement.current = activeElement(doc);

@@ -142,5 +112,5 @@ if (focusOnMount) {

}
return function () {
var isBodyInactive = restoreFocusElement.current !== doc.body;
var hasActiveElement = restoreFocusElement.current !== null;
return () => {
const isBodyInactive = restoreFocusElement.current !== doc.body;
const hasActiveElement = restoreFocusElement.current !== null;
if (isBodyInactive && hasActiveElement && restoreFocus) {

@@ -152,13 +122,13 @@ focusElement(restoreFocusElement.current);

return {
getContainerProps: getContainerProps,
focusElement: focusElement
getContainerProps,
focusElement
};
};
var _excluded = ["children", "render"];
var FocusJailContainer = function FocusJailContainer(_ref) {
var children = _ref.children,
_ref$render = _ref.render,
render = _ref$render === void 0 ? children : _ref$render,
options = _objectWithoutPropertiesLoose(_ref, _excluded);
const FocusJailContainer = _ref => {
let {
children,
render = children,
...options
} = _ref;
return React.createElement(React.Fragment, null, render(useFocusJail(options)));

@@ -165,0 +135,0 @@ };

{
"name": "@zendeskgarden/container-focusjail",
"version": "2.0.0",
"version": "2.0.1",
"description": "Containers relating to focusjail in the Garden Design System",

@@ -24,5 +24,5 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.8.4",
"@zendeskgarden/container-utilities": "^1.0.0",
"@zendeskgarden/container-utilities": "^1.0.1",
"dom-helpers": "^5.1.0",
"tabbable": "^5.0.0"
"tabbable": "^6.0.0"
},

@@ -47,3 +47,3 @@ "peerDependencies": {

"zendeskgarden:src": "src/index.ts",
"gitHead": "9d58d7c857d5b21a8d90558be2f2be341b2a9270"
"gitHead": "621beb216c03789ed99aa39ed0f2897fa2e52368"
}
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