reshaped 3.8.0-canary.9 → 3.8.0

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 (78) hide show
  1. package/dist/bundle.css +1 -1
  2. package/dist/bundle.d.ts +2 -1
  3. package/dist/bundle.js +9 -9
  4. package/dist/components/Badge/Badge.js +2 -2
  5. package/dist/components/Badge/Badge.module.css +1 -1
  6. package/dist/components/Badge/Badge.types.d.ts +2 -0
  7. package/dist/components/Badge/tests/Badge.stories.d.ts +4 -0
  8. package/dist/components/Badge/tests/Badge.stories.js +10 -0
  9. package/dist/components/Button/Button.module.css +1 -1
  10. package/dist/components/Button/tests/Button.stories.js +1 -1
  11. package/dist/components/DropdownMenu/tests/DropdownMenu.stories.d.ts +1 -1
  12. package/dist/components/DropdownMenu/tests/DropdownMenu.stories.js +21 -4
  13. package/dist/components/Flyout/index.d.ts +1 -1
  14. package/dist/components/Hidden/Hidden.js +1 -2
  15. package/dist/components/Modal/tests/Modal.stories.d.ts +3 -7
  16. package/dist/components/Modal/tests/Modal.stories.js +5 -22
  17. package/dist/components/NumberField/NumberFieldControlled.js +22 -22
  18. package/dist/components/Resizable/Resizable.js +3 -4
  19. package/dist/components/Select/Select.js +1 -0
  20. package/dist/components/Select/SelectCustomControlled.js +6 -3
  21. package/dist/components/Select/SelectOption.js +0 -2
  22. package/dist/components/Select/SelectOptionGroup.js +0 -2
  23. package/dist/components/Table/Table.js +5 -6
  24. package/dist/components/Tabs/Tabs.module.css +1 -1
  25. package/dist/components/Tabs/TabsItem.js +1 -1
  26. package/dist/components/Tabs/TabsList.js +3 -20
  27. package/dist/components/Text/Text.module.css +1 -1
  28. package/dist/components/TextField/TextField.js +10 -2
  29. package/dist/components/TextField/TextField.module.css +1 -1
  30. package/dist/components/TextField/TextField.types.d.ts +5 -1
  31. package/dist/components/TextField/tests/TextField.stories.js +11 -5
  32. package/dist/components/Timeline/Timeline.js +3 -4
  33. package/dist/components/Toast/tests/Toast.stories.js +1 -1
  34. package/dist/components/ToggleButton/ToggleButton.types.d.ts +5 -1
  35. package/dist/components/ToggleButton/ToggleButtonControlled.js +9 -2
  36. package/dist/components/ToggleButton/tests/ToggleButton.stories.d.ts +4 -0
  37. package/dist/components/ToggleButton/tests/ToggleButton.stories.js +10 -0
  38. package/dist/components/ToggleButtonGroup/ToggleButtonGroup.types.d.ts +10 -0
  39. package/dist/components/ToggleButtonGroup/ToggleButtonGroupControlled.js +6 -42
  40. package/dist/components/ToggleButtonGroup/tests/ToggleButtonGroup.stories.d.ts +1 -0
  41. package/dist/components/ToggleButtonGroup/tests/ToggleButtonGroup.stories.js +17 -0
  42. package/dist/components/Tooltip/Tooltip.js +1 -1
  43. package/dist/components/Tooltip/Tooltip.types.d.ts +2 -2
  44. package/dist/components/View/View.js +11 -7
  45. package/dist/components/View/View.types.d.ts +1 -1
  46. package/dist/hooks/tests/useKeyboardArrowNavigation.stories.d.ts +15 -0
  47. package/dist/hooks/tests/useKeyboardArrowNavigation.stories.js +128 -0
  48. package/dist/hooks/useKeyboardArrowNavigation.d.ts +9 -0
  49. package/dist/hooks/useKeyboardArrowNavigation.js +62 -0
  50. package/dist/hooks/useOnClickOutside.js +0 -2
  51. package/dist/hooks/useScrollLock.js +5 -3
  52. package/dist/index.d.ts +2 -1
  53. package/dist/index.js +1 -0
  54. package/dist/utilities/a11y/focus.d.ts +21 -4
  55. package/dist/utilities/a11y/focus.js +4 -3
  56. package/dist/utilities/props.d.ts +0 -3
  57. package/dist/utilities/props.js +0 -19
  58. package/dist/utilities/scroll/index.d.ts +1 -1
  59. package/dist/utilities/scroll/index.js +1 -1
  60. package/dist/utilities/scroll/lock.d.ts +1 -2
  61. package/dist/utilities/scroll/lock.js +14 -15
  62. package/package.json +195 -201
  63. package/CHANGELOG-extra.md +0 -3
  64. package/CHANGELOG.md +0 -121
  65. package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.d.ts +0 -21
  66. package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.js +0 -11
  67. package/dist/components/Link/tests/Link.test.stories.d.ts +0 -17
  68. package/dist/components/Link/tests/Link.test.stories.js +0 -11
  69. package/dist/components/Loader/tests/Loader.test.stories.d.ts +0 -13
  70. package/dist/components/Loader/tests/Loader.test.stories.js +0 -11
  71. package/dist/components/Table/tests/Table.test.stories.d.ts +0 -19
  72. package/dist/components/Table/tests/Table.test.stories.js +0 -11
  73. package/dist/components/TextField/tests/TextField.test.stories.d.ts +0 -15
  74. package/dist/components/TextField/tests/TextField.test.stories.js +0 -11
  75. package/dist/components/Timeline/tests/Timeline.test.stories.d.ts +0 -15
  76. package/dist/components/Timeline/tests/Timeline.test.stories.js +0 -11
  77. package/dist/components/Tooltip/tests/Tooltip.test.stories.d.ts +0 -13
  78. package/dist/components/Tooltip/tests/Tooltip.test.stories.js +0 -11
@@ -0,0 +1,128 @@
1
+ import React, { useRef } from "react";
2
+ import { expect, userEvent } from "storybook/test";
3
+ import View from "../../components/View/index.js";
4
+ import Button from "../../components/Button/index.js";
5
+ import useKeyboardArrowNavigation from "../useKeyboardArrowNavigation.js";
6
+ export default {
7
+ title: "Hooks/useKeyboardArrowNavigation",
8
+ parameters: {
9
+ chromatic: { disableSnapshot: true },
10
+ },
11
+ };
12
+ export const base = {
13
+ name: "base",
14
+ render: () => {
15
+ const ref = useRef(null);
16
+ useKeyboardArrowNavigation({ ref });
17
+ return (<View gap={2} direction="row" attributes={{ ref }}>
18
+ <Button onClick={() => { }}>Action 1</Button>
19
+ <Button onClick={() => { }}>Action 2</Button>
20
+ <Button onClick={() => { }}>Action 3</Button>
21
+ </View>);
22
+ },
23
+ play: async ({ canvas }) => {
24
+ const buttons = canvas.getAllByRole("button");
25
+ buttons[0].focus();
26
+ await userEvent.keyboard("{ArrowRight/}");
27
+ expect(document.activeElement).toBe(buttons[1]);
28
+ await userEvent.keyboard("{ArrowDown/}");
29
+ expect(document.activeElement).toBe(buttons[2]);
30
+ await userEvent.keyboard("{ArrowUp/}");
31
+ expect(document.activeElement).toBe(buttons[1]);
32
+ await userEvent.keyboard("{ArrowLeft/}");
33
+ expect(document.activeElement).toBe(buttons[0]);
34
+ },
35
+ };
36
+ export const horizontal = {
37
+ name: "orientation: horizontal",
38
+ render: () => {
39
+ const ref = useRef(null);
40
+ useKeyboardArrowNavigation({ ref, orientation: "horizontal" });
41
+ return (<View gap={2} direction="row" attributes={{ ref }}>
42
+ <Button onClick={() => { }}>Action 1</Button>
43
+ <Button onClick={() => { }}>Action 2</Button>
44
+ <Button onClick={() => { }}>Action 3</Button>
45
+ </View>);
46
+ },
47
+ play: async ({ canvas }) => {
48
+ const buttons = canvas.getAllByRole("button");
49
+ expect(buttons[0]).toHaveAttribute("tabindex", "0");
50
+ expect(buttons[1]).toHaveAttribute("tabindex", "-1");
51
+ expect(buttons[2]).toHaveAttribute("tabindex", "-1");
52
+ buttons[0].focus();
53
+ await userEvent.keyboard("{ArrowRight/}");
54
+ expect(document.activeElement).toBe(buttons[1]);
55
+ await userEvent.keyboard("{ArrowLeft/}");
56
+ expect(document.activeElement).toBe(buttons[0]);
57
+ await userEvent.keyboard("{ArrowDown/}");
58
+ expect(document.activeElement).toBe(buttons[0]);
59
+ await userEvent.keyboard("{ArrowUp/}");
60
+ expect(document.activeElement).toBe(buttons[0]);
61
+ },
62
+ };
63
+ export const vertical = {
64
+ name: "orientation: vertical",
65
+ render: () => {
66
+ const ref = useRef(null);
67
+ useKeyboardArrowNavigation({ ref, orientation: "vertical" });
68
+ return (<View gap={2} direction="column" attributes={{ ref }}>
69
+ <Button onClick={() => { }}>Action 1</Button>
70
+ <Button onClick={() => { }}>Action 2</Button>
71
+ <Button onClick={() => { }}>Action 3</Button>
72
+ </View>);
73
+ },
74
+ play: async ({ canvas }) => {
75
+ const buttons = canvas.getAllByRole("button");
76
+ buttons[0].focus();
77
+ await userEvent.keyboard("{ArrowDown/}");
78
+ expect(document.activeElement).toBe(buttons[1]);
79
+ await userEvent.keyboard("{ArrowUp/}");
80
+ expect(document.activeElement).toBe(buttons[0]);
81
+ await userEvent.keyboard("{ArrowRight/}");
82
+ expect(document.activeElement).toBe(buttons[0]);
83
+ await userEvent.keyboard("{ArrowLeft/}");
84
+ expect(document.activeElement).toBe(buttons[0]);
85
+ },
86
+ };
87
+ export const circular = {
88
+ name: "circular",
89
+ render: () => {
90
+ const ref = useRef(null);
91
+ useKeyboardArrowNavigation({ ref, circular: true });
92
+ return (<View gap={2} direction="row" attributes={{ ref }}>
93
+ <Button onClick={() => { }}>Action 1</Button>
94
+ <Button onClick={() => { }}>Action 2</Button>
95
+ <Button onClick={() => { }}>Action 3</Button>
96
+ </View>);
97
+ },
98
+ play: async ({ canvas }) => {
99
+ const buttons = canvas.getAllByRole("button");
100
+ buttons[0].focus();
101
+ await userEvent.keyboard("{ArrowRight/}");
102
+ await userEvent.keyboard("{ArrowRight/}");
103
+ expect(document.activeElement).toBe(buttons[2]);
104
+ await userEvent.keyboard("{ArrowRight/}");
105
+ expect(document.activeElement).toBe(buttons[0]);
106
+ await userEvent.keyboard("{ArrowLeft/}");
107
+ expect(document.activeElement).toBe(buttons[2]);
108
+ },
109
+ };
110
+ export const disabled = {
111
+ name: "disabled",
112
+ render: () => {
113
+ const ref = useRef(null);
114
+ useKeyboardArrowNavigation({ ref, disabled: true });
115
+ return (<View gap={2} direction="row" attributes={{ ref }}>
116
+ <Button onClick={() => { }}>Action 1</Button>
117
+ <Button onClick={() => { }}>Action 2</Button>
118
+ <Button onClick={() => { }}>Action 3</Button>
119
+ </View>);
120
+ },
121
+ play: async ({ canvas }) => {
122
+ const buttons = canvas.getAllByRole("button");
123
+ buttons[0].focus();
124
+ await userEvent.keyboard("{ArrowRight/}");
125
+ expect(document.activeElement).toBe(buttons[0]);
126
+ expect(buttons[0]).not.toHaveAttribute("tabindex");
127
+ },
128
+ };
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ type Props = {
3
+ ref: React.RefObject<HTMLElement | null>;
4
+ disabled?: boolean;
5
+ orientation?: "vertical" | "horizontal";
6
+ circular?: boolean;
7
+ };
8
+ declare const useKeyboardArrowNavigation: (props: Props) => void;
9
+ export default useKeyboardArrowNavigation;
@@ -0,0 +1,62 @@
1
+ import React, { useEffect } from "react";
2
+ import { focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getFocusableElements, } from "../utilities/a11y/index.js";
3
+ import useHotkeys from "./useHotkeys.js";
4
+ const useKeyboardArrowNavigation = (props) => {
5
+ const { ref, disabled, orientation, circular } = props;
6
+ const backHotkeys = [];
7
+ const forwardHotkeys = [];
8
+ if (!orientation || orientation === "vertical") {
9
+ backHotkeys.push("ArrowUp");
10
+ forwardHotkeys.push("ArrowDown");
11
+ }
12
+ if (!orientation || orientation === "horizontal") {
13
+ backHotkeys.push("ArrowLeft");
14
+ forwardHotkeys.push("ArrowRight");
15
+ }
16
+ const updateTabIndex = React.useCallback((options) => {
17
+ const { el, focusableElements } = options;
18
+ const initialEl = focusableElements.find((el) => el.getAttribute("tabindex") !== "-1");
19
+ const activeEl = el ?? initialEl ?? focusableElements[0];
20
+ focusableElements.forEach((el) => el.setAttribute("tabindex", "-1"));
21
+ activeEl?.setAttribute("tabindex", "0");
22
+ }, []);
23
+ useEffect(() => {
24
+ if (!ref.current)
25
+ return;
26
+ if (disabled)
27
+ return;
28
+ const focusableElements = getFocusableElements(ref.current);
29
+ updateTabIndex({ focusableElements });
30
+ }, [ref, updateTabIndex, disabled]);
31
+ useHotkeys({
32
+ [backHotkeys.join(", ")]: () => {
33
+ if (!ref.current)
34
+ return;
35
+ const data = focusPreviousElement(ref.current, { circular });
36
+ updateTabIndex(data);
37
+ },
38
+ [forwardHotkeys.join(", ")]: () => {
39
+ if (!ref.current)
40
+ return;
41
+ const data = focusNextElement(ref.current, { circular });
42
+ updateTabIndex(data);
43
+ },
44
+ Home: () => {
45
+ if (!ref.current)
46
+ return;
47
+ const data = focusFirstElement(ref.current);
48
+ updateTabIndex(data);
49
+ },
50
+ End: () => {
51
+ if (!ref.current)
52
+ return;
53
+ const data = focusLastElement(ref.current);
54
+ updateTabIndex(data);
55
+ },
56
+ }, [updateTabIndex, circular], {
57
+ ref,
58
+ preventDefault: true,
59
+ disabled,
60
+ });
61
+ };
62
+ export default useKeyboardArrowNavigation;
@@ -39,8 +39,6 @@ const useOnClickOutside = (refs, handler, options) => {
39
39
  if (disabled)
40
40
  return;
41
41
  const handleClick = (event) => {
42
- if (!event.pointerType)
43
- return;
44
42
  if (event.button === 2)
45
43
  return;
46
44
  if (isMouseDownInsideRef.current)
@@ -1,18 +1,20 @@
1
1
  "use client";
2
2
  import React from "react";
3
- import { lockScroll, unlockScroll } from "../utilities/scroll/index.js";
3
+ import { lockScroll } from "../utilities/scroll/index.js";
4
4
  const useScrollLock = (options) => {
5
5
  const { containerRef, originRef } = options || {};
6
6
  const [locked, setLocked] = React.useState(false);
7
+ const unlockScrollRef = React.useRef(null);
7
8
  const handleLockScroll = React.useCallback(() => {
8
- lockScroll({
9
+ unlockScrollRef.current = lockScroll({
9
10
  containerEl: containerRef?.current,
10
11
  originEl: originRef?.current,
11
12
  cb: () => setLocked(true),
12
13
  });
13
14
  }, [containerRef, originRef]);
14
15
  const handleUnlockScroll = React.useCallback(() => {
15
- unlockScroll(() => setLocked(false));
16
+ unlockScrollRef.current?.(() => setLocked(false));
17
+ unlockScrollRef.current = null;
16
18
  }, []);
17
19
  return React.useMemo(() => ({
18
20
  scrollLocked: locked,
package/dist/index.d.ts CHANGED
@@ -103,7 +103,7 @@ export type { ContainerProps } from "./components/Container";
103
103
  export { default as Dismissible } from "./components/Dismissible";
104
104
  export type { DismissibleProps } from "./components/Dismissible";
105
105
  export { default as Flyout } from "./components/Flyout";
106
- export type { FlyoutProps, FlyoutInstance } from "./components/Flyout";
106
+ export type { FlyoutProps, FlyoutInstance, FlyoutTriggerAttributes } from "./components/Flyout";
107
107
  export { default as FormControl } from "./components/FormControl";
108
108
  export type { FormControlProps } from "./components/FormControl";
109
109
  export { default as Grid } from "./components/Grid";
@@ -135,6 +135,7 @@ export { default as useHandlerRef } from "./hooks/useHandlerRef";
135
135
  export { default as useHotkeys } from "./hooks/useHotkeys";
136
136
  export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect";
137
137
  export { default as useKeyboardMode } from "./hooks/useKeyboardMode";
138
+ export { default as useKeyboardArrowNavigation } from "./hooks/useKeyboardArrowNavigation";
138
139
  export { default as useOnClickOutside } from "./hooks/useOnClickOutside";
139
140
  export { default as useResponsiveClientValue } from "./hooks/useResponsiveClientValue";
140
141
  export { default as useRTL } from "./hooks/useRTL";
package/dist/index.js CHANGED
@@ -74,6 +74,7 @@ export { default as useHandlerRef } from "./hooks/useHandlerRef.js";
74
74
  export { default as useHotkeys } from "./hooks/useHotkeys.js";
75
75
  export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect.js";
76
76
  export { default as useKeyboardMode } from "./hooks/useKeyboardMode.js";
77
+ export { default as useKeyboardArrowNavigation } from "./hooks/useKeyboardArrowNavigation.js";
77
78
  export { default as useOnClickOutside } from "./hooks/useOnClickOutside.js";
78
79
  export { default as useResponsiveClientValue } from "./hooks/useResponsiveClientValue.js";
79
80
  export { default as useRTL } from "./hooks/useRTL.js";
@@ -14,8 +14,25 @@ export declare const getFocusData: (args: {
14
14
  }) => {
15
15
  overflow: boolean;
16
16
  el: FocusableElement;
17
+ focusableElements: FocusableElement[];
18
+ };
19
+ export declare const focusNextElement: (root: HTMLElement, options?: {
20
+ circular?: boolean;
21
+ }) => {
22
+ el: FocusableElement;
23
+ focusableElements: FocusableElement[];
24
+ };
25
+ export declare const focusPreviousElement: (root: HTMLElement, options?: {
26
+ circular?: boolean;
27
+ }) => {
28
+ el: FocusableElement;
29
+ focusableElements: FocusableElement[];
30
+ };
31
+ export declare const focusFirstElement: (root: HTMLElement) => {
32
+ el: FocusableElement;
33
+ focusableElements: FocusableElement[];
34
+ };
35
+ export declare const focusLastElement: (root: HTMLElement) => {
36
+ el: FocusableElement;
37
+ focusableElements: FocusableElement[];
17
38
  };
18
- export declare const focusNextElement: (root: HTMLElement) => void;
19
- export declare const focusPreviousElement: (root: HTMLElement) => void;
20
- export declare const focusFirstElement: (root: HTMLElement) => void;
21
- export declare const focusLastElement: (root: HTMLElement) => void;
@@ -88,13 +88,14 @@ export const getFocusData = (args) => {
88
88
  nextIndex = target === "prev" ? positions.first : positions.last;
89
89
  }
90
90
  }
91
- return { overflow: isOverflow, el: focusable[nextIndex] };
91
+ return { overflow: isOverflow, el: focusable[nextIndex], focusableElements: focusable };
92
92
  };
93
93
  const focusTargetElement = (root, target, options) => {
94
94
  const data = getFocusData({ root, target, options });
95
95
  focusElement(data.el);
96
+ return { el: data.el, focusableElements: data.focusableElements };
96
97
  };
97
- export const focusNextElement = (root) => focusTargetElement(root, "next", { includeNegativeTabIndex: true });
98
- export const focusPreviousElement = (root) => focusTargetElement(root, "prev", { includeNegativeTabIndex: true });
98
+ export const focusNextElement = (root, options) => focusTargetElement(root, "next", { ...options, includeNegativeTabIndex: true });
99
+ export const focusPreviousElement = (root, options) => focusTargetElement(root, "prev", { ...options, includeNegativeTabIndex: true });
99
100
  export const focusFirstElement = (root) => focusTargetElement(root, "first", { includeNegativeTabIndex: true });
100
101
  export const focusLastElement = (root) => focusTargetElement(root, "last", { includeNegativeTabIndex: true });
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import type * as G from "../types/global";
3
2
  type Value = string | boolean | number | undefined;
4
3
  type ClassNameResolver = string | ((value: Value) => string);
@@ -11,6 +10,4 @@ export declare const responsiveClassNames: <V extends G.Responsive<Value>>(s: Re
11
10
  }) => string[];
12
11
  export declare const responsiveVariables: <V extends Value = Value>(variableName: G.CSSVariable, value?: G.Responsive<V>) => Record<G.CSSVariable, V>;
13
12
  export declare const responsivePropDependency: <Result, T>(prop: G.Responsive<T>, resolver: (value: T, key: G.Viewport) => Result) => Result;
14
- export declare const setComponentChildId: (Component: React.FC<any>, id: string) => string;
15
- export declare const isMatchingComponentChildId: (child: React.ReactNode, id: string) => boolean | null;
16
13
  export {};
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  /**
3
2
  * Resolve an array of values into a classname string
4
3
  */
@@ -82,21 +81,3 @@ export const responsivePropDependency = (prop, resolver) => {
82
81
  return { ...acc, [viewport]: resolver(viewportValue, viewport) };
83
82
  }, {});
84
83
  };
85
- /**
86
- * Add unique ids to components relying on React.Children.map
87
- * Relying on an id instead of child.type makes it work in dev mode during HMR
88
- */
89
- const getComponentChildId = (id) => `__rs-child-${id}`;
90
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- export const setComponentChildId = (Component, id) => {
92
- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
93
- // @ts-ignore
94
- return (Component.__reshapedChildId = getComponentChildId(id));
95
- };
96
- export const isMatchingComponentChildId = (child, id) => {
97
- if (!React.isValidElement(child))
98
- return null;
99
- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
100
- // @ts-ignore
101
- return child.type.__reshapedChildId === getComponentChildId(id);
102
- };
@@ -1,2 +1,2 @@
1
1
  export { disableScroll, enableScroll } from "./disable";
2
- export { lockScroll, unlockScroll } from "./lock";
2
+ export { lockScroll } from "./lock";
@@ -1,2 +1,2 @@
1
1
  export { disableScroll, enableScroll } from "./disable.js";
2
- export { lockScroll, unlockScroll } from "./lock.js";
2
+ export { lockScroll } from "./lock.js";
@@ -2,5 +2,4 @@ export declare const lockScroll: (args: {
2
2
  containerEl?: HTMLElement | null;
3
3
  originEl?: HTMLElement | null;
4
4
  cb?: () => void;
5
- }) => void;
6
- export declare const unlockScroll: (cb?: () => void) => void;
5
+ }) => ((cb?: () => void) => void) | undefined;
@@ -3,31 +3,30 @@ import { findClosestScrollableContainer } from "../dom/index.js";
3
3
  import lockSafariScroll from "./lockSafari.js";
4
4
  import lockStandardScroll from "./lockStandard.js";
5
5
  let bodyLockedCount = 0;
6
- let reset = () => { };
7
6
  export const lockScroll = (args) => {
8
- const isIOSLock = isIOS() && !args.containerEl && !args.originEl;
7
+ const isIOSLock = isIOS();
8
+ let reset = () => { };
9
9
  let container = document.body;
10
- if (args.originEl && !isIOSLock) {
10
+ if (args.originEl)
11
11
  container = findClosestScrollableContainer({ el: args.originEl });
12
- }
13
- if (args.containerEl && !isIOSLock)
12
+ if (args.containerEl)
14
13
  container = args.containerEl;
15
- if (container === document.body)
14
+ const lockedBodyScroll = container === document.body;
15
+ if (lockedBodyScroll)
16
16
  bodyLockedCount += 1;
17
- if (bodyLockedCount > 1)
17
+ if (lockedBodyScroll && bodyLockedCount > 1)
18
18
  return;
19
- if (isIOSLock) {
19
+ if (isIOSLock && lockedBodyScroll) {
20
20
  reset = lockSafariScroll();
21
21
  }
22
22
  else {
23
23
  reset = lockStandardScroll({ container });
24
24
  }
25
25
  args.cb?.();
26
- };
27
- export const unlockScroll = (cb) => {
28
- bodyLockedCount -= 1;
29
- if (bodyLockedCount > 0)
30
- return;
31
- reset();
32
- cb?.();
26
+ return (cb) => {
27
+ if (lockedBodyScroll)
28
+ bodyLockedCount -= 1;
29
+ reset();
30
+ cb?.();
31
+ };
33
32
  };