react-focus-on 3.9.4 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/es2015/Effect.d.ts +1 -1
  2. package/dist/es2015/Effect.js +18 -28
  3. package/dist/es2015/UI.js +13 -5
  4. package/dist/es2015/package.json +1 -0
  5. package/dist/es2015/stories/Button.d.ts +15 -0
  6. package/dist/es2015/stories/Button.js +10 -0
  7. package/dist/es2015/stories/Button.stories.d.ts +8 -0
  8. package/dist/es2015/stories/Button.stories.js +44 -0
  9. package/dist/es2015/stories/Header.d.ts +12 -0
  10. package/dist/es2015/stories/Header.js +8 -0
  11. package/dist/es2015/stories/Header.stories.d.ts +6 -0
  12. package/dist/es2015/stories/Header.stories.js +26 -0
  13. package/dist/es2015/stories/Page.d.ts +3 -0
  14. package/dist/es2015/stories/Page.js +8 -0
  15. package/dist/es2015/stories/Page.stories.d.ts +6 -0
  16. package/dist/es2015/stories/Page.stories.js +41 -0
  17. package/dist/es2015/types.d.ts +1 -0
  18. package/dist/es5/Effect.d.ts +1 -1
  19. package/dist/es5/Effect.js +17 -27
  20. package/dist/es5/UI.js +13 -5
  21. package/dist/es5/stories/Button.d.ts +15 -0
  22. package/dist/es5/stories/Button.js +13 -0
  23. package/dist/es5/stories/Button.stories.d.ts +8 -0
  24. package/dist/es5/stories/Button.stories.js +47 -0
  25. package/dist/es5/stories/Header.d.ts +12 -0
  26. package/dist/es5/stories/Header.js +11 -0
  27. package/dist/es5/stories/Header.stories.d.ts +6 -0
  28. package/dist/es5/stories/Header.stories.js +29 -0
  29. package/dist/es5/stories/Page.d.ts +3 -0
  30. package/dist/es5/stories/Page.js +13 -0
  31. package/dist/es5/stories/Page.stories.d.ts +6 -0
  32. package/dist/es5/stories/Page.stories.js +44 -0
  33. package/dist/es5/types.d.ts +1 -0
  34. package/package.json +10 -12
  35. package/dist/es2015/component.d.ts +0 -2
  36. package/dist/es2015/component.js +0 -12
  37. package/dist/es5/component.d.ts +0 -2
  38. package/dist/es5/component.js +0 -16
@@ -1,2 +1,2 @@
1
1
  import { EffectProps } from './types';
2
- export declare function Effect({ setLockProps, onEscapeKey, onClickOutside, shards, onActivation, onDeactivation, noIsolation }: EffectProps): JSX.Element;
2
+ export declare function Effect({ setLockProps, onEscapeKey, onClickOutside, shards, onActivation, onDeactivation, noIsolation, activeNode, }: EffectProps): JSX.Element;
@@ -3,13 +3,12 @@ import * as React from 'react';
3
3
  import { hideOthers } from 'aria-hidden';
4
4
  import { InteractivityDisabler } from './InteractivityDisabler';
5
5
  import { focusHiddenMarker } from './medium';
6
- import { useEffect, useRef, useState } from 'react';
6
+ import { useEffect, useRef } from 'react';
7
7
  var extractRef = function (ref) {
8
8
  return 'current' in ref ? ref.current : ref;
9
9
  };
10
10
  export function Effect(_a) {
11
- var setLockProps = _a.setLockProps, onEscapeKey = _a.onEscapeKey, onClickOutside = _a.onClickOutside, shards = _a.shards, onActivation = _a.onActivation, onDeactivation = _a.onDeactivation, noIsolation = _a.noIsolation;
12
- var _b = useState(undefined), activeNode = _b[0], setActiveNode = _b[1];
11
+ var setLockProps = _a.setLockProps, onEscapeKey = _a.onEscapeKey, onClickOutside = _a.onClickOutside, shards = _a.shards, onActivation = _a.onActivation, onDeactivation = _a.onDeactivation, noIsolation = _a.noIsolation, activeNode = _a.activeNode;
13
12
  var lastEventTarget = useRef(null);
14
13
  var mouseTouches = useRef(0);
15
14
  React.useEffect(function () {
@@ -50,17 +49,18 @@ export function Effect(_a) {
50
49
  mouseTouches.current = event.touches.length;
51
50
  };
52
51
  if (activeNode) {
53
- document.addEventListener('keydown', onKeyDown);
54
- document.addEventListener('mousedown', onMouseDown);
55
- document.addEventListener('touchstart', onTouchStart);
56
- document.addEventListener('touchend', onTouchEnd);
52
+ activeNode.ownerDocument.addEventListener('keydown', onKeyDown);
53
+ activeNode.ownerDocument.addEventListener('mousedown', onMouseDown);
54
+ activeNode.ownerDocument.addEventListener('touchstart', onTouchStart);
55
+ activeNode.ownerDocument.addEventListener('touchend', onTouchEnd);
57
56
  return function () {
58
- document.removeEventListener('keydown', onKeyDown);
59
- document.removeEventListener('mousedown', onMouseDown);
60
- document.removeEventListener('touchstart', onTouchStart);
61
- document.removeEventListener('touchend', onTouchEnd);
57
+ activeNode.ownerDocument.removeEventListener('keydown', onKeyDown);
58
+ activeNode.ownerDocument.removeEventListener('mousedown', onMouseDown);
59
+ activeNode.ownerDocument.removeEventListener('touchstart', onTouchStart);
60
+ activeNode.ownerDocument.removeEventListener('touchend', onTouchEnd);
62
61
  };
63
62
  }
63
+ return;
64
64
  }, [activeNode, onClickOutside, onEscapeKey]);
65
65
  useEffect(function () {
66
66
  if (activeNode) {
@@ -73,22 +73,15 @@ export function Effect(_a) {
73
73
  }
74
74
  };
75
75
  }
76
+ return;
76
77
  }, [!!activeNode]);
77
78
  useEffect(function () {
78
- var _undo = function () { return null; };
79
- var unmounted = false;
80
- var onNodeActivation = function (node) {
81
- if (!noIsolation) {
82
- _undo = hideOthers(__spreadArrays([node], (shards || []).map(extractRef)), document.body, focusHiddenMarker);
83
- }
84
- setActiveNode(function () { return node; });
85
- };
86
- var onNodeDeactivation = function () {
87
- _undo();
88
- if (!unmounted) {
89
- setActiveNode(null);
90
- }
91
- };
79
+ if (noIsolation || !activeNode) {
80
+ return;
81
+ }
82
+ return hideOthers(__spreadArrays([activeNode], (shards || []).map(extractRef)), activeNode.ownerDocument.body, focusHiddenMarker);
83
+ }, [activeNode, noIsolation]);
84
+ useEffect(function () {
92
85
  setLockProps({
93
86
  onMouseDown: function (e) {
94
87
  lastEventTarget.current = e.target;
@@ -96,11 +89,8 @@ export function Effect(_a) {
96
89
  onTouchStart: function (e) {
97
90
  lastEventTarget.current = e.target;
98
91
  },
99
- onActivation: onNodeActivation,
100
- onDeactivation: onNodeDeactivation
101
92
  });
102
93
  return function () {
103
- unmounted = true;
104
94
  setLockProps(false);
105
95
  };
106
96
  }, []);
package/dist/es2015/UI.js CHANGED
@@ -6,18 +6,26 @@ import { effectCar } from './medium';
6
6
  var PREVENT_SCROLL = { preventScroll: true };
7
7
  export var FocusOn = React.forwardRef(function (props, parentRef) {
8
8
  var _a = React.useState(false), lockProps = _a[0], setLockProps = _a[1];
9
- var children = props.children, autoFocus = props.autoFocus, shards = props.shards, crossFrame = props.crossFrame, _b = props.enabled, enabled = _b === void 0 ? true : _b, _c = props.scrollLock, scrollLock = _c === void 0 ? true : _c, _d = props.focusLock, focusLock = _d === void 0 ? true : _d, _e = props.returnFocus, returnFocus = _e === void 0 ? true : _e, inert = props.inert, allowPinchZoom = props.allowPinchZoom, sideCar = props.sideCar, className = props.className, shouldIgnore = props.shouldIgnore, preventScrollOnFocus = props.preventScrollOnFocus, style = props.style, as = props.as, gapMode = props.gapMode, rest = __rest(props, ["children", "autoFocus", "shards", "crossFrame", "enabled", "scrollLock", "focusLock", "returnFocus", "inert", "allowPinchZoom", "sideCar", "className", "shouldIgnore", "preventScrollOnFocus", "style", "as", "gapMode"]);
9
+ var _b = React.useState(null), activeNode = _b[0], setActiveNode = _b[1];
10
+ var children = props.children, autoFocus = props.autoFocus, shards = props.shards, crossFrame = props.crossFrame, _c = props.enabled, enabled = _c === void 0 ? true : _c, _d = props.scrollLock, scrollLock = _d === void 0 ? true : _d, _e = props.focusLock, focusLock = _e === void 0 ? true : _e, _f = props.returnFocus, returnFocus = _f === void 0 ? true : _f, inert = props.inert, allowPinchZoom = props.allowPinchZoom, sideCar = props.sideCar, className = props.className, shouldIgnore = props.shouldIgnore, preventScrollOnFocus = props.preventScrollOnFocus, style = props.style, as = props.as, gapMode = props.gapMode, rest = __rest(props, ["children", "autoFocus", "shards", "crossFrame", "enabled", "scrollLock", "focusLock", "returnFocus", "inert", "allowPinchZoom", "sideCar", "className", "shouldIgnore", "preventScrollOnFocus", "style", "as", "gapMode"]);
10
11
  var SideCar = sideCar;
11
- var onActivation = lockProps.onActivation, onDeactivation = lockProps.onDeactivation, restProps = __rest(lockProps, ["onActivation", "onDeactivation"]);
12
- var appliedLockProps = __assign(__assign({}, restProps), { as: as,
12
+ var appliedLockProps = __assign(__assign({}, lockProps), { as: as,
13
13
  style: style,
14
14
  sideCar: sideCar,
15
15
  shards: shards,
16
16
  allowPinchZoom: allowPinchZoom,
17
17
  gapMode: gapMode,
18
18
  inert: inert, enabled: enabled && scrollLock });
19
+ var onActivation = React.useCallback(function (node) {
20
+ setActiveNode(node);
21
+ }, []);
22
+ var onDeactivation = React.useCallback(function () {
23
+ setActiveNode(null);
24
+ }, []);
19
25
  return (React.createElement(React.Fragment, null,
20
- React.createElement(ReactFocusLock, { ref: parentRef, sideCar: sideCar, disabled: !(lockProps && enabled && focusLock), returnFocus: returnFocus, autoFocus: autoFocus, shards: shards, crossFrame: crossFrame, onActivation: onActivation, onDeactivation: onDeactivation, className: className, whiteList: shouldIgnore, lockProps: appliedLockProps, focusOptions: preventScrollOnFocus ? PREVENT_SCROLL : undefined, as: RemoveScroll }, children),
21
- enabled && (React.createElement(SideCar, __assign({}, rest, { sideCar: effectCar, setLockProps: setLockProps, shards: shards })))));
26
+ React.createElement(ReactFocusLock, { ref: parentRef, sideCar: sideCar, disabled: !(enabled && focusLock), returnFocus: returnFocus, autoFocus: autoFocus, shards: shards, crossFrame: crossFrame, onActivation: onActivation, onDeactivation: onDeactivation, className: className, whiteList: shouldIgnore, lockProps: appliedLockProps, focusOptions: preventScrollOnFocus ? PREVENT_SCROLL : undefined,
27
+ // // ts-expect-error TS2322 - ts v3 "glitch"
28
+ as: RemoveScroll }, children),
29
+ enabled && (React.createElement(SideCar, __assign({}, rest, { sideCar: effectCar, setLockProps: setLockProps, shards: shards, activeNode: activeNode })))));
22
30
  });
23
31
  export * from './reExports';
@@ -0,0 +1 @@
1
+ {"type": "module"}
@@ -0,0 +1,15 @@
1
+ import './button.css';
2
+ export interface ButtonProps {
3
+ /** Is this the principal call to action on the page? */
4
+ primary?: boolean;
5
+ /** What background color to use */
6
+ backgroundColor?: string;
7
+ /** How large should the button be? */
8
+ size?: 'small' | 'medium' | 'large';
9
+ /** Button contents */
10
+ label: string;
11
+ /** Optional click handler */
12
+ onClick?: () => void;
13
+ }
14
+ /** Primary UI component for user interaction */
15
+ export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { __assign, __rest } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React from 'react';
4
+ import './button.css';
5
+ /** Primary UI component for user interaction */
6
+ export var Button = function (_a) {
7
+ var _b = _a.primary, primary = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ? 'medium' : _c, backgroundColor = _a.backgroundColor, label = _a.label, props = __rest(_a, ["primary", "size", "backgroundColor", "label"]);
8
+ var mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
9
+ return (_jsx("button", __assign({ type: "button", className: ['storybook-button', "storybook-button--".concat(size), mode].join(' '), style: { backgroundColor: backgroundColor } }, props, { children: label })));
10
+ };
@@ -0,0 +1,8 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: Meta<({ primary, size, backgroundColor, label, ...props }: import("./Button").ButtonProps) => JSX.Element>;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const Primary: Story;
6
+ export declare const Secondary: Story;
7
+ export declare const Large: Story;
8
+ export declare const Small: Story;
@@ -0,0 +1,44 @@
1
+ import { fn } from 'storybook/test';
2
+ import { Button } from './Button';
3
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
4
+ var meta = {
5
+ title: 'Example/Button',
6
+ component: Button,
7
+ parameters: {
8
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
9
+ layout: 'centered',
10
+ },
11
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
12
+ tags: ['autodocs'],
13
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
14
+ argTypes: {
15
+ backgroundColor: { control: 'color' },
16
+ },
17
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
18
+ args: { onClick: fn() },
19
+ };
20
+ export default meta;
21
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
22
+ export var Primary = {
23
+ args: {
24
+ primary: true,
25
+ label: 'Button',
26
+ },
27
+ };
28
+ export var Secondary = {
29
+ args: {
30
+ label: 'Button',
31
+ },
32
+ };
33
+ export var Large = {
34
+ args: {
35
+ size: 'large',
36
+ label: 'Button',
37
+ },
38
+ };
39
+ export var Small = {
40
+ args: {
41
+ size: 'small',
42
+ label: 'Button',
43
+ },
44
+ };
@@ -0,0 +1,12 @@
1
+ import './header.css';
2
+ type User = {
3
+ name: string;
4
+ };
5
+ export interface HeaderProps {
6
+ user?: User;
7
+ onLogin?: () => void;
8
+ onLogout?: () => void;
9
+ onCreateAccount?: () => void;
10
+ }
11
+ export declare const Header: ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => JSX.Element;
12
+ export {};
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { Button } from './Button';
4
+ import './header.css';
5
+ export var Header = function (_a) {
6
+ var user = _a.user, onLogin = _a.onLogin, onLogout = _a.onLogout, onCreateAccount = _a.onCreateAccount;
7
+ return (_jsx("header", { children: _jsxs("div", { className: "storybook-header", children: [_jsxs("div", { children: [_jsx("svg", { width: "32", height: "32", viewBox: "0 0 32 32", xmlns: "http://www.w3.org/2000/svg", children: _jsxs("g", { fill: "none", fillRule: "evenodd", children: [_jsx("path", { d: "M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z", fill: "#FFF" }), _jsx("path", { d: "M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z", fill: "#555AB9" }), _jsx("path", { d: "M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z", fill: "#91BAF8" })] }) }), _jsx("h1", { children: "Acme" })] }), _jsx("div", { children: user ? (_jsxs(_Fragment, { children: [_jsxs("span", { className: "welcome", children: ["Welcome, ", _jsx("b", { children: user.name }), "!"] }), _jsx(Button, { size: "small", onClick: onLogout, label: "Log out" })] })) : (_jsxs(_Fragment, { children: [_jsx(Button, { size: "small", onClick: onLogin, label: "Log in" }), _jsx(Button, { primary: true, size: "small", onClick: onCreateAccount, label: "Sign up" })] })) })] }) }));
8
+ };
@@ -0,0 +1,6 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: Meta<({ user, onLogin, onLogout, onCreateAccount }: import("./Header").HeaderProps) => JSX.Element>;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const LoggedIn: Story;
6
+ export declare const LoggedOut: Story;
@@ -0,0 +1,26 @@
1
+ import { fn } from 'storybook/test';
2
+ import { Header } from './Header';
3
+ var meta = {
4
+ title: 'Example/Header',
5
+ component: Header,
6
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
7
+ tags: ['autodocs'],
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ args: {
13
+ onLogin: fn(),
14
+ onLogout: fn(),
15
+ onCreateAccount: fn(),
16
+ },
17
+ };
18
+ export default meta;
19
+ export var LoggedIn = {
20
+ args: {
21
+ user: {
22
+ name: 'Jane Doe',
23
+ },
24
+ },
25
+ };
26
+ export var LoggedOut = {};
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import './page.css';
3
+ export declare const Page: React.FC;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { Header } from './Header';
4
+ import './page.css';
5
+ export var Page = function () {
6
+ var _a = React.useState(), user = _a[0], setUser = _a[1];
7
+ return (_jsxs("article", { children: [_jsx(Header, { user: user, onLogin: function () { return setUser({ name: 'Jane Doe' }); }, onLogout: function () { return setUser(undefined); }, onCreateAccount: function () { return setUser({ name: 'Jane Doe' }); } }), _jsxs("section", { className: "storybook-page", children: [_jsx("h2", { children: "Pages in Storybook" }), _jsxs("p", { children: ["We recommend building UIs with a", ' ', _jsx("a", { href: "https://componentdriven.org", target: "_blank", rel: "noopener noreferrer", children: _jsx("strong", { children: "component-driven" }) }), ' ', "process starting with atomic components and ending with pages."] }), _jsx("p", { children: "Render pages with mock data. This makes it easy to build and review page states without needing to navigate to them in your app. Here are some handy patterns for managing page data in Storybook:" }), _jsxs("ul", { children: [_jsx("li", { children: "Use a higher-level connected component. Storybook helps you compose such data from the \"args\" of child component stories" }), _jsx("li", { children: "Assemble data in the page component from your services. You can mock these services out using Storybook." })] }), _jsxs("p", { children: ["Get a guided tutorial on component-driven development at", ' ', _jsx("a", { href: "https://storybook.js.org/tutorials/", target: "_blank", rel: "noopener noreferrer", children: "Storybook tutorials" }), ". Read more in the", ' ', _jsx("a", { href: "https://storybook.js.org/docs", target: "_blank", rel: "noopener noreferrer", children: "docs" }), "."] }), _jsxs("div", { className: "tip-wrapper", children: [_jsx("span", { className: "tip", children: "Tip" }), " Adjust the width of the canvas with the", ' ', _jsx("svg", { width: "10", height: "10", viewBox: "0 0 12 12", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", fillRule: "evenodd", children: _jsx("path", { d: "M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z", id: "a", fill: "#999" }) }) }), "Viewports addon in the toolbar"] })] })] }));
8
+ };
@@ -0,0 +1,6 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: Meta<import("react").FC<{}>>;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const LoggedOut: Story;
6
+ export declare const LoggedIn: Story;
@@ -0,0 +1,41 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { expect, userEvent, within } from 'storybook/test';
3
+ import { Page } from './Page';
4
+ var meta = {
5
+ title: 'Example/Page',
6
+ component: Page,
7
+ parameters: {
8
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
9
+ layout: 'fullscreen',
10
+ },
11
+ };
12
+ export default meta;
13
+ export var LoggedOut = {};
14
+ // More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
15
+ export var LoggedIn = {
16
+ play: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
17
+ var canvas, loginButton, logoutButton;
18
+ var canvasElement = _b.canvasElement;
19
+ return __generator(this, function (_c) {
20
+ switch (_c.label) {
21
+ case 0:
22
+ canvas = within(canvasElement);
23
+ loginButton = canvas.getByRole('button', { name: /Log in/i });
24
+ return [4 /*yield*/, expect(loginButton).toBeInTheDocument()];
25
+ case 1:
26
+ _c.sent();
27
+ return [4 /*yield*/, userEvent.click(loginButton)];
28
+ case 2:
29
+ _c.sent();
30
+ return [4 /*yield*/, expect(loginButton).not.toBeInTheDocument()];
31
+ case 3:
32
+ _c.sent();
33
+ logoutButton = canvas.getByRole('button', { name: /Log out/i });
34
+ return [4 /*yield*/, expect(logoutButton).toBeInTheDocument()];
35
+ case 4:
36
+ _c.sent();
37
+ return [2 /*return*/];
38
+ }
39
+ });
40
+ }); },
41
+ };
@@ -108,4 +108,5 @@ export interface ReactFocusOnSideProps extends ReactFocusOnProps {
108
108
  }
109
109
  export interface EffectProps extends CommonProps {
110
110
  setLockProps(settings: LockProps): void;
111
+ activeNode: HTMLElement | null;
111
112
  }
@@ -1,2 +1,2 @@
1
1
  import { EffectProps } from './types';
2
- export declare function Effect({ setLockProps, onEscapeKey, onClickOutside, shards, onActivation, onDeactivation, noIsolation }: EffectProps): JSX.Element;
2
+ export declare function Effect({ setLockProps, onEscapeKey, onClickOutside, shards, onActivation, onDeactivation, noIsolation, activeNode, }: EffectProps): JSX.Element;
@@ -11,8 +11,7 @@ var extractRef = function (ref) {
11
11
  return 'current' in ref ? ref.current : ref;
12
12
  };
13
13
  function Effect(_a) {
14
- var setLockProps = _a.setLockProps, onEscapeKey = _a.onEscapeKey, onClickOutside = _a.onClickOutside, shards = _a.shards, onActivation = _a.onActivation, onDeactivation = _a.onDeactivation, noIsolation = _a.noIsolation;
15
- var _b = react_1.useState(undefined), activeNode = _b[0], setActiveNode = _b[1];
14
+ var setLockProps = _a.setLockProps, onEscapeKey = _a.onEscapeKey, onClickOutside = _a.onClickOutside, shards = _a.shards, onActivation = _a.onActivation, onDeactivation = _a.onDeactivation, noIsolation = _a.noIsolation, activeNode = _a.activeNode;
16
15
  var lastEventTarget = react_1.useRef(null);
17
16
  var mouseTouches = react_1.useRef(0);
18
17
  React.useEffect(function () {
@@ -53,17 +52,18 @@ function Effect(_a) {
53
52
  mouseTouches.current = event.touches.length;
54
53
  };
55
54
  if (activeNode) {
56
- document.addEventListener('keydown', onKeyDown);
57
- document.addEventListener('mousedown', onMouseDown);
58
- document.addEventListener('touchstart', onTouchStart);
59
- document.addEventListener('touchend', onTouchEnd);
55
+ activeNode.ownerDocument.addEventListener('keydown', onKeyDown);
56
+ activeNode.ownerDocument.addEventListener('mousedown', onMouseDown);
57
+ activeNode.ownerDocument.addEventListener('touchstart', onTouchStart);
58
+ activeNode.ownerDocument.addEventListener('touchend', onTouchEnd);
60
59
  return function () {
61
- document.removeEventListener('keydown', onKeyDown);
62
- document.removeEventListener('mousedown', onMouseDown);
63
- document.removeEventListener('touchstart', onTouchStart);
64
- document.removeEventListener('touchend', onTouchEnd);
60
+ activeNode.ownerDocument.removeEventListener('keydown', onKeyDown);
61
+ activeNode.ownerDocument.removeEventListener('mousedown', onMouseDown);
62
+ activeNode.ownerDocument.removeEventListener('touchstart', onTouchStart);
63
+ activeNode.ownerDocument.removeEventListener('touchend', onTouchEnd);
65
64
  };
66
65
  }
66
+ return;
67
67
  }, [activeNode, onClickOutside, onEscapeKey]);
68
68
  react_1.useEffect(function () {
69
69
  if (activeNode) {
@@ -76,22 +76,15 @@ function Effect(_a) {
76
76
  }
77
77
  };
78
78
  }
79
+ return;
79
80
  }, [!!activeNode]);
80
81
  react_1.useEffect(function () {
81
- var _undo = function () { return null; };
82
- var unmounted = false;
83
- var onNodeActivation = function (node) {
84
- if (!noIsolation) {
85
- _undo = aria_hidden_1.hideOthers(tslib_1.__spreadArrays([node], (shards || []).map(extractRef)), document.body, medium_1.focusHiddenMarker);
86
- }
87
- setActiveNode(function () { return node; });
88
- };
89
- var onNodeDeactivation = function () {
90
- _undo();
91
- if (!unmounted) {
92
- setActiveNode(null);
93
- }
94
- };
82
+ if (noIsolation || !activeNode) {
83
+ return;
84
+ }
85
+ return aria_hidden_1.hideOthers(tslib_1.__spreadArrays([activeNode], (shards || []).map(extractRef)), activeNode.ownerDocument.body, medium_1.focusHiddenMarker);
86
+ }, [activeNode, noIsolation]);
87
+ react_1.useEffect(function () {
95
88
  setLockProps({
96
89
  onMouseDown: function (e) {
97
90
  lastEventTarget.current = e.target;
@@ -99,11 +92,8 @@ function Effect(_a) {
99
92
  onTouchStart: function (e) {
100
93
  lastEventTarget.current = e.target;
101
94
  },
102
- onActivation: onNodeActivation,
103
- onDeactivation: onNodeDeactivation
104
95
  });
105
96
  return function () {
106
- unmounted = true;
107
97
  setLockProps(false);
108
98
  };
109
99
  }, []);
package/dist/es5/UI.js CHANGED
@@ -9,18 +9,26 @@ var medium_1 = require("./medium");
9
9
  var PREVENT_SCROLL = { preventScroll: true };
10
10
  exports.FocusOn = React.forwardRef(function (props, parentRef) {
11
11
  var _a = React.useState(false), lockProps = _a[0], setLockProps = _a[1];
12
- var children = props.children, autoFocus = props.autoFocus, shards = props.shards, crossFrame = props.crossFrame, _b = props.enabled, enabled = _b === void 0 ? true : _b, _c = props.scrollLock, scrollLock = _c === void 0 ? true : _c, _d = props.focusLock, focusLock = _d === void 0 ? true : _d, _e = props.returnFocus, returnFocus = _e === void 0 ? true : _e, inert = props.inert, allowPinchZoom = props.allowPinchZoom, sideCar = props.sideCar, className = props.className, shouldIgnore = props.shouldIgnore, preventScrollOnFocus = props.preventScrollOnFocus, style = props.style, as = props.as, gapMode = props.gapMode, rest = tslib_1.__rest(props, ["children", "autoFocus", "shards", "crossFrame", "enabled", "scrollLock", "focusLock", "returnFocus", "inert", "allowPinchZoom", "sideCar", "className", "shouldIgnore", "preventScrollOnFocus", "style", "as", "gapMode"]);
12
+ var _b = React.useState(null), activeNode = _b[0], setActiveNode = _b[1];
13
+ var children = props.children, autoFocus = props.autoFocus, shards = props.shards, crossFrame = props.crossFrame, _c = props.enabled, enabled = _c === void 0 ? true : _c, _d = props.scrollLock, scrollLock = _d === void 0 ? true : _d, _e = props.focusLock, focusLock = _e === void 0 ? true : _e, _f = props.returnFocus, returnFocus = _f === void 0 ? true : _f, inert = props.inert, allowPinchZoom = props.allowPinchZoom, sideCar = props.sideCar, className = props.className, shouldIgnore = props.shouldIgnore, preventScrollOnFocus = props.preventScrollOnFocus, style = props.style, as = props.as, gapMode = props.gapMode, rest = tslib_1.__rest(props, ["children", "autoFocus", "shards", "crossFrame", "enabled", "scrollLock", "focusLock", "returnFocus", "inert", "allowPinchZoom", "sideCar", "className", "shouldIgnore", "preventScrollOnFocus", "style", "as", "gapMode"]);
13
14
  var SideCar = sideCar;
14
- var onActivation = lockProps.onActivation, onDeactivation = lockProps.onDeactivation, restProps = tslib_1.__rest(lockProps, ["onActivation", "onDeactivation"]);
15
- var appliedLockProps = tslib_1.__assign(tslib_1.__assign({}, restProps), { as: as,
15
+ var appliedLockProps = tslib_1.__assign(tslib_1.__assign({}, lockProps), { as: as,
16
16
  style: style,
17
17
  sideCar: sideCar,
18
18
  shards: shards,
19
19
  allowPinchZoom: allowPinchZoom,
20
20
  gapMode: gapMode,
21
21
  inert: inert, enabled: enabled && scrollLock });
22
+ var onActivation = React.useCallback(function (node) {
23
+ setActiveNode(node);
24
+ }, []);
25
+ var onDeactivation = React.useCallback(function () {
26
+ setActiveNode(null);
27
+ }, []);
22
28
  return (React.createElement(React.Fragment, null,
23
- React.createElement(UI_2.default, { ref: parentRef, sideCar: sideCar, disabled: !(lockProps && enabled && focusLock), returnFocus: returnFocus, autoFocus: autoFocus, shards: shards, crossFrame: crossFrame, onActivation: onActivation, onDeactivation: onDeactivation, className: className, whiteList: shouldIgnore, lockProps: appliedLockProps, focusOptions: preventScrollOnFocus ? PREVENT_SCROLL : undefined, as: UI_1.RemoveScroll }, children),
24
- enabled && (React.createElement(SideCar, tslib_1.__assign({}, rest, { sideCar: medium_1.effectCar, setLockProps: setLockProps, shards: shards })))));
29
+ React.createElement(UI_2.default, { ref: parentRef, sideCar: sideCar, disabled: !(enabled && focusLock), returnFocus: returnFocus, autoFocus: autoFocus, shards: shards, crossFrame: crossFrame, onActivation: onActivation, onDeactivation: onDeactivation, className: className, whiteList: shouldIgnore, lockProps: appliedLockProps, focusOptions: preventScrollOnFocus ? PREVENT_SCROLL : undefined,
30
+ // // ts-expect-error TS2322 - ts v3 "glitch"
31
+ as: UI_1.RemoveScroll }, children),
32
+ enabled && (React.createElement(SideCar, tslib_1.__assign({}, rest, { sideCar: medium_1.effectCar, setLockProps: setLockProps, shards: shards, activeNode: activeNode })))));
25
33
  });
26
34
  tslib_1.__exportStar(require("./reExports"), exports);
@@ -0,0 +1,15 @@
1
+ import './button.css';
2
+ export interface ButtonProps {
3
+ /** Is this the principal call to action on the page? */
4
+ primary?: boolean;
5
+ /** What background color to use */
6
+ backgroundColor?: string;
7
+ /** How large should the button be? */
8
+ size?: 'small' | 'medium' | 'large';
9
+ /** Button contents */
10
+ label: string;
11
+ /** Optional click handler */
12
+ onClick?: () => void;
13
+ }
14
+ /** Primary UI component for user interaction */
15
+ export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => JSX.Element;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Button = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ require("./button.css");
7
+ /** Primary UI component for user interaction */
8
+ var Button = function (_a) {
9
+ var _b = _a.primary, primary = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ? 'medium' : _c, backgroundColor = _a.backgroundColor, label = _a.label, props = tslib_1.__rest(_a, ["primary", "size", "backgroundColor", "label"]);
10
+ var mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
11
+ return ((0, jsx_runtime_1.jsx)("button", tslib_1.__assign({ type: "button", className: ['storybook-button', "storybook-button--".concat(size), mode].join(' '), style: { backgroundColor: backgroundColor } }, props, { children: label })));
12
+ };
13
+ exports.Button = Button;
@@ -0,0 +1,8 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: Meta<({ primary, size, backgroundColor, label, ...props }: import("./Button").ButtonProps) => JSX.Element>;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const Primary: Story;
6
+ export declare const Secondary: Story;
7
+ export declare const Large: Story;
8
+ export declare const Small: Story;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Small = exports.Large = exports.Secondary = exports.Primary = void 0;
4
+ var test_1 = require("storybook/test");
5
+ var Button_1 = require("./Button");
6
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
7
+ var meta = {
8
+ title: 'Example/Button',
9
+ component: Button_1.Button,
10
+ parameters: {
11
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
12
+ layout: 'centered',
13
+ },
14
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
15
+ tags: ['autodocs'],
16
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
17
+ argTypes: {
18
+ backgroundColor: { control: 'color' },
19
+ },
20
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
21
+ args: { onClick: (0, test_1.fn)() },
22
+ };
23
+ exports.default = meta;
24
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
25
+ exports.Primary = {
26
+ args: {
27
+ primary: true,
28
+ label: 'Button',
29
+ },
30
+ };
31
+ exports.Secondary = {
32
+ args: {
33
+ label: 'Button',
34
+ },
35
+ };
36
+ exports.Large = {
37
+ args: {
38
+ size: 'large',
39
+ label: 'Button',
40
+ },
41
+ };
42
+ exports.Small = {
43
+ args: {
44
+ size: 'small',
45
+ label: 'Button',
46
+ },
47
+ };
@@ -0,0 +1,12 @@
1
+ import './header.css';
2
+ type User = {
3
+ name: string;
4
+ };
5
+ export interface HeaderProps {
6
+ user?: User;
7
+ onLogin?: () => void;
8
+ onLogout?: () => void;
9
+ onCreateAccount?: () => void;
10
+ }
11
+ export declare const Header: ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => JSX.Element;
12
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Header = void 0;
4
+ var jsx_runtime_1 = require("react/jsx-runtime");
5
+ var Button_1 = require("./Button");
6
+ require("./header.css");
7
+ var Header = function (_a) {
8
+ var user = _a.user, onLogin = _a.onLogin, onLogout = _a.onLogout, onCreateAccount = _a.onCreateAccount;
9
+ return ((0, jsx_runtime_1.jsx)("header", { children: (0, jsx_runtime_1.jsxs)("div", { className: "storybook-header", children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("svg", { width: "32", height: "32", viewBox: "0 0 32 32", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsxs)("g", { fill: "none", fillRule: "evenodd", children: [(0, jsx_runtime_1.jsx)("path", { d: "M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z", fill: "#FFF" }), (0, jsx_runtime_1.jsx)("path", { d: "M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z", fill: "#555AB9" }), (0, jsx_runtime_1.jsx)("path", { d: "M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z", fill: "#91BAF8" })] }) }), (0, jsx_runtime_1.jsx)("h1", { children: "Acme" })] }), (0, jsx_runtime_1.jsx)("div", { children: user ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("span", { className: "welcome", children: ["Welcome, ", (0, jsx_runtime_1.jsx)("b", { children: user.name }), "!"] }), (0, jsx_runtime_1.jsx)(Button_1.Button, { size: "small", onClick: onLogout, label: "Log out" })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button_1.Button, { size: "small", onClick: onLogin, label: "Log in" }), (0, jsx_runtime_1.jsx)(Button_1.Button, { primary: true, size: "small", onClick: onCreateAccount, label: "Sign up" })] })) })] }) }));
10
+ };
11
+ exports.Header = Header;
@@ -0,0 +1,6 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: Meta<({ user, onLogin, onLogout, onCreateAccount }: import("./Header").HeaderProps) => JSX.Element>;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const LoggedIn: Story;
6
+ export declare const LoggedOut: Story;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggedOut = exports.LoggedIn = void 0;
4
+ var test_1 = require("storybook/test");
5
+ var Header_1 = require("./Header");
6
+ var meta = {
7
+ title: 'Example/Header',
8
+ component: Header_1.Header,
9
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
10
+ tags: ['autodocs'],
11
+ parameters: {
12
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
13
+ layout: 'fullscreen',
14
+ },
15
+ args: {
16
+ onLogin: (0, test_1.fn)(),
17
+ onLogout: (0, test_1.fn)(),
18
+ onCreateAccount: (0, test_1.fn)(),
19
+ },
20
+ };
21
+ exports.default = meta;
22
+ exports.LoggedIn = {
23
+ args: {
24
+ user: {
25
+ name: 'Jane Doe',
26
+ },
27
+ },
28
+ };
29
+ exports.LoggedOut = {};
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import './page.css';
3
+ export declare const Page: React.FC;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Page = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ var react_1 = tslib_1.__importDefault(require("react"));
7
+ var Header_1 = require("./Header");
8
+ require("./page.css");
9
+ var Page = function () {
10
+ var _a = react_1.default.useState(), user = _a[0], setUser = _a[1];
11
+ return ((0, jsx_runtime_1.jsxs)("article", { children: [(0, jsx_runtime_1.jsx)(Header_1.Header, { user: user, onLogin: function () { return setUser({ name: 'Jane Doe' }); }, onLogout: function () { return setUser(undefined); }, onCreateAccount: function () { return setUser({ name: 'Jane Doe' }); } }), (0, jsx_runtime_1.jsxs)("section", { className: "storybook-page", children: [(0, jsx_runtime_1.jsx)("h2", { children: "Pages in Storybook" }), (0, jsx_runtime_1.jsxs)("p", { children: ["We recommend building UIs with a", ' ', (0, jsx_runtime_1.jsx)("a", { href: "https://componentdriven.org", target: "_blank", rel: "noopener noreferrer", children: (0, jsx_runtime_1.jsx)("strong", { children: "component-driven" }) }), ' ', "process starting with atomic components and ending with pages."] }), (0, jsx_runtime_1.jsx)("p", { children: "Render pages with mock data. This makes it easy to build and review page states without needing to navigate to them in your app. Here are some handy patterns for managing page data in Storybook:" }), (0, jsx_runtime_1.jsxs)("ul", { children: [(0, jsx_runtime_1.jsx)("li", { children: "Use a higher-level connected component. Storybook helps you compose such data from the \"args\" of child component stories" }), (0, jsx_runtime_1.jsx)("li", { children: "Assemble data in the page component from your services. You can mock these services out using Storybook." })] }), (0, jsx_runtime_1.jsxs)("p", { children: ["Get a guided tutorial on component-driven development at", ' ', (0, jsx_runtime_1.jsx)("a", { href: "https://storybook.js.org/tutorials/", target: "_blank", rel: "noopener noreferrer", children: "Storybook tutorials" }), ". Read more in the", ' ', (0, jsx_runtime_1.jsx)("a", { href: "https://storybook.js.org/docs", target: "_blank", rel: "noopener noreferrer", children: "docs" }), "."] }), (0, jsx_runtime_1.jsxs)("div", { className: "tip-wrapper", children: [(0, jsx_runtime_1.jsx)("span", { className: "tip", children: "Tip" }), " Adjust the width of the canvas with the", ' ', (0, jsx_runtime_1.jsx)("svg", { width: "10", height: "10", viewBox: "0 0 12 12", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("g", { fill: "none", fillRule: "evenodd", children: (0, jsx_runtime_1.jsx)("path", { d: "M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z", id: "a", fill: "#999" }) }) }), "Viewports addon in the toolbar"] })] })] }));
12
+ };
13
+ exports.Page = Page;
@@ -0,0 +1,6 @@
1
+ import type { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: Meta<import("react").FC<{}>>;
3
+ export default meta;
4
+ type Story = StoryObj<typeof meta>;
5
+ export declare const LoggedOut: Story;
6
+ export declare const LoggedIn: Story;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggedIn = exports.LoggedOut = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var test_1 = require("storybook/test");
6
+ var Page_1 = require("./Page");
7
+ var meta = {
8
+ title: 'Example/Page',
9
+ component: Page_1.Page,
10
+ parameters: {
11
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ };
15
+ exports.default = meta;
16
+ exports.LoggedOut = {};
17
+ // More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
18
+ exports.LoggedIn = {
19
+ play: function (_a) { return tslib_1.__awaiter(void 0, [_a], void 0, function (_b) {
20
+ var canvas, loginButton, logoutButton;
21
+ var canvasElement = _b.canvasElement;
22
+ return tslib_1.__generator(this, function (_c) {
23
+ switch (_c.label) {
24
+ case 0:
25
+ canvas = (0, test_1.within)(canvasElement);
26
+ loginButton = canvas.getByRole('button', { name: /Log in/i });
27
+ return [4 /*yield*/, (0, test_1.expect)(loginButton).toBeInTheDocument()];
28
+ case 1:
29
+ _c.sent();
30
+ return [4 /*yield*/, test_1.userEvent.click(loginButton)];
31
+ case 2:
32
+ _c.sent();
33
+ return [4 /*yield*/, (0, test_1.expect)(loginButton).not.toBeInTheDocument()];
34
+ case 3:
35
+ _c.sent();
36
+ logoutButton = canvas.getByRole('button', { name: /Log out/i });
37
+ return [4 /*yield*/, (0, test_1.expect)(logoutButton).toBeInTheDocument()];
38
+ case 4:
39
+ _c.sent();
40
+ return [2 /*return*/];
41
+ }
42
+ });
43
+ }); },
44
+ };
@@ -108,4 +108,5 @@ export interface ReactFocusOnSideProps extends ReactFocusOnProps {
108
108
  }
109
109
  export interface EffectProps extends CommonProps {
110
110
  setLockProps(settings: LockProps): void;
111
+ activeNode: HTMLElement | null;
111
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-focus-on",
3
- "version": "3.9.4",
3
+ "version": "3.10.1",
4
4
  "description": "The final solution for WAI ARIA compatible modal dialogs or full-screen tasks.",
5
5
  "main": "dist/es5/index.js",
6
6
  "scripts": {
@@ -44,19 +44,19 @@
44
44
  "ts-react-toolbox": "^0.2.10"
45
45
  },
46
46
  "dependencies": {
47
- "aria-hidden": "^1.2.2",
48
- "react-focus-lock": "^2.11.3",
49
- "react-remove-scroll": "^2.6.0",
50
- "react-style-singleton": "^2.2.1",
47
+ "aria-hidden": "^1.2.5",
48
+ "react-focus-lock": "^2.13.7",
49
+ "react-remove-scroll": "^2.6.4",
50
+ "react-style-singleton": "^2.2.3",
51
51
  "tslib": "^2.3.1",
52
- "use-sidecar": "^1.1.2"
52
+ "use-sidecar": "^1.1.3"
53
53
  },
54
54
  "engines": {
55
55
  "node": ">=8.5.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0",
59
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
58
+ "@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
59
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@types/react": {
@@ -78,8 +78,6 @@
78
78
  "scroll",
79
79
  "isolation"
80
80
  ],
81
- "resolutions": {
82
- "typescript": "^3.8.0"
83
- },
84
- "homepage": "https://github.com/theKashey/react-focus-on#readme"
81
+ "homepage": "https://github.com/theKashey/react-focus-on#readme",
82
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
85
83
  }
@@ -1,2 +0,0 @@
1
- import { ReactFocusOnSideProps } from "./types";
2
- export declare function ReactFocusOn(props: ReactFocusOnSideProps): JSX.Element;
@@ -1,12 +0,0 @@
1
- import * as React from 'react';
2
- import { RemoveScroll } from 'react-remove-scroll/UI';
3
- import ReactFocusLock from 'react-focus-lock/UI';
4
- var extractRef = function (ref) { return (('current' in ref) ? ref.current : ref); };
5
- export function ReactFocusOn(props) {
6
- var _a = React.useState(null), lockProps = _a[0], setLockProps = _a[1];
7
- var _b = this.props, children = _b.children, autoFocus = _b.autoFocus, shards = _b.shards, _c = _b.enabled, enabled = _c === void 0 ? true : _c, _d = _b.scrollLock, scrollLock = _d === void 0 ? true : _d, _e = _b.focusLock, focusLock = _e === void 0 ? true : _e, sideCar = _b.sideCar;
8
- return (React.createElement(React.Fragment, null,
9
- React.createElement(RemoveScroll, { sideCar: enabled && sideCar, enabled: enabled && scrollLock, shards: shards },
10
- enabled && React.createElement(Effect, null),
11
- React.createElement(ReactFocusLock, { sideCar: enabled && sideCar, disabled: !(this.state.lockProps && enabled && focusLock), returnFocus: true, autoFocus: autoFocus, onActivation: this.onActivation, onDeactivation: this.onDeactivation, shards: shards, lockProps: lockProps }, children))));
12
- }
@@ -1,2 +0,0 @@
1
- import { ReactFocusOnSideProps } from "./types";
2
- export declare function ReactFocusOn(props: ReactFocusOnSideProps): JSX.Element;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var React = require("react");
4
- var UI_1 = require("react-remove-scroll/UI");
5
- var UI_2 = require("react-focus-lock/UI");
6
- var InteractivityDisabler_1 = require("./InteractivityDisabler");
7
- var extractRef = function (ref) { return (('current' in ref) ? ref.current : ref); };
8
- function ReactFocusOn(props) {
9
- var _a = React.useState(null), lockProps = _a[0], setLockProps = _a[1];
10
- var _b = this.props, children = _b.children, autoFocus = _b.autoFocus, shards = _b.shards, _c = _b.enabled, enabled = _c === void 0 ? true : _c, _d = _b.scrollLock, scrollLock = _d === void 0 ? true : _d, _e = _b.focusLock, focusLock = _e === void 0 ? true : _e, sideCar = _b.sideCar;
11
- return (React.createElement(React.Fragment, null,
12
- React.createElement(UI_1.RemoveScroll, { sideCar: enabled && sideCar, enabled: enabled && scrollLock, shards: shards },
13
- enabled && React.createElement(InteractivityDisabler_1.InteractivityDisabler, null),
14
- React.createElement(UI_2.default, { sideCar: enabled && sideCar, disabled: !(this.state.lockProps && enabled && focusLock), returnFocus: true, autoFocus: autoFocus, onActivation: this.onActivation, onDeactivation: this.onDeactivation, shards: shards, lockProps: lockProps }, children))));
15
- }
16
- exports.ReactFocusOn = ReactFocusOn;