diff --git a/CHANGELOG.md b/CHANGELOG.md index 807af9e..daff17a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [2.8.1](https://github.com/theKashey/react-focus-lock/compare/v2.8.0...v2.8.1) (2022-02-14) + + +### Bug Fixes + +* correct shadow-dom specification, fixes [#188](https://github.com/theKashey/react-focus-lock/issues/188) ([159bb98](https://github.com/theKashey/react-focus-lock/commit/159bb9861265793117524eb43a7475fc2c96c994)) + + + # [2.8.0](https://github.com/theKashey/react-focus-lock/compare/v2.7.1...v2.8.0) (2022-02-14) diff --git a/interfaces.d.ts b/interfaces.d.ts index 57c57ac..06d10f4 100644 --- a/interfaces.d.ts +++ b/interfaces.d.ts @@ -117,6 +117,7 @@ export interface AutoFocusProps { } export interface FreeFocusProps { + children: React.ReactNode; className?: string; } diff --git a/package.json b/package.json index ad3ddef..78e6a0e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,13 @@ "url": "https://github.com/theKashey/react-focus-lock/issues" }, "peerDependencies": { - "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + "react": "^16.8.0 || ^17.0.0 || ^18.0.0", + "@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } }, "devDependencies": { "@babel/cli": "^7.0.0", @@ -64,7 +70,7 @@ "@storybook/addon-actions": "^5.1.8", "@storybook/addon-links": "^5.1.8", "@storybook/react": "^5.1.8", - "@types/react": "^16.8.19", + "@types/react": "^18.0.8", "babel-eslint": "^10.0.1", "babel-loader": "^8.0.4", "babel-plugin-transform-react-remove-prop-types": "^0.4.19", diff --git a/src/Trap.js b/src/Trap.js index de1ebf8..7933084 100644 --- a/src/Trap.js +++ b/src/Trap.js @@ -1,9 +1,10 @@ +/* eslint-disable no-mixed-operators */ import * as React from 'react'; import PropTypes from 'prop-types'; import withSideEffect from 'react-clientside-effect'; -import moveFocusInside, {focusInside, focusIsHidden, getFocusabledIn} from 'focus-lock'; -import {deferAction} from './util'; -import {mediumFocus, mediumBlur, mediumEffect} from './medium'; +import moveFocusInside, { focusInside, focusIsHidden, getFocusabledIn } from 'focus-lock'; +import { deferAction } from './util'; +import { mediumFocus, mediumBlur, mediumEffect } from './medium'; const focusOnBody = () => ( document && document.activeElement === document.body @@ -25,7 +26,7 @@ const focusWhitelisted = activeElement => ( ); const recordPortal = (observerNode, portaledElement) => { - lastPortaledElement = {observerNode, portaledElement}; + lastPortaledElement = { observerNode, portaledElement }; }; const focusIsPortaledPair = element => ( @@ -68,15 +69,16 @@ const focusWasOutside = (crossFrameOption) => { }; const checkInHost = (check, el, boundary) => ( - el + el && ( // find host equal to active element and check nested active element - && (el.host === check && (!el.activeElement || boundary.contains(el.activeElement)) + (el.host === check && (!el.activeElement || boundary.contains(el.activeElement)) // dive up - || el.parentNode && checkInHost(check, el.parentNode, boundary))) + || (el.parentNode && checkInHost(check, el.parentNode, boundary)))) +); -const withinHost = (activeElement, workingArea) => { - return workingArea.some(area => checkInHost(activeElement, area, area)) -} +const withinHost = (activeElement, workingArea) => ( + workingArea.some(area => checkInHost(activeElement, area, area)) +); const activateTrap = () => { let result = false; @@ -103,8 +105,8 @@ const activateTrap = () => { && !( // active element is "inside" working area (focusInside(workingArea) || ( - // check for shadow-dom contained elements - activeElement && withinHost(activeElement, workingArea)) + // check for shadow-dom contained elements + activeElement && withinHost(activeElement, workingArea)) ) || focusIsPortaledPair(activeElement, workingNode) ) @@ -116,7 +118,7 @@ const activateTrap = () => { } document.body.focus(); } else { - result = moveFocusInside(workingArea, lastActiveFocus, {focusOptions}); + result = moveFocusInside(workingArea, lastActiveFocus, { focusOptions }); lastPortaledElement = {}; } } @@ -128,12 +130,12 @@ const activateTrap = () => { if (document) { const newActiveElement = document && document.activeElement; const allNodes = getFocusabledIn(workingArea); - const focusedIndex = allNodes.map(({node}) => node).indexOf(newActiveElement); + const focusedIndex = allNodes.map(({ node }) => node).indexOf(newActiveElement); if (focusedIndex > -1) { // remove old focus allNodes - .filter(({guard, node}) => guard && node.dataset.focusAutoGuard) - .forEach(({node}) => node.removeAttribute('tabIndex')); + .filter(({ guard, node }) => guard && node.dataset.focusAutoGuard) + .forEach(({ node }) => node.removeAttribute('tabIndex')); autoGuard(focusedIndex, allNodes.length, +1, allNodes); autoGuard(focusedIndex, -1, -1, allNodes); @@ -167,7 +169,7 @@ const onFocus = (event) => { const FocusWatcher = () => null; -const FocusTrap = ({children}) => ( +const FocusTrap = ({ children }) => (