@reshaped/utilities 3.9.1-canary.3 → 3.10.0-canary.5
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.
- package/README.md +232 -0
- package/dist/a11y/Chain.d.ts +20 -0
- package/dist/a11y/Chain.js +60 -0
- package/dist/a11y/TrapFocus.d.ts +28 -0
- package/dist/a11y/TrapFocus.js +162 -0
- package/dist/a11y/TrapScreenReader.d.ts +15 -0
- package/dist/a11y/TrapScreenReader.js +42 -0
- package/dist/a11y/focus.d.ts +38 -0
- package/dist/a11y/focus.js +101 -0
- package/dist/a11y/index.d.ts +4 -0
- package/dist/a11y/index.js +3 -0
- package/dist/a11y/keyboardMode.d.ts +4 -0
- package/dist/a11y/keyboardMode.js +10 -0
- package/dist/a11y/tests/Chain.test.js +88 -0
- package/dist/a11y/tests/TrapFocus.test.d.ts +1 -0
- package/dist/a11y/tests/TrapFocus.test.js +313 -0
- package/dist/a11y/tests/TrapScreenReader.test.d.ts +1 -0
- package/dist/a11y/tests/TrapScreenReader.test.js +126 -0
- package/dist/a11y/tests/focus.test.d.ts +1 -0
- package/dist/a11y/tests/focus.test.js +278 -0
- package/dist/a11y/tests/keyboardMode.test.d.ts +1 -0
- package/dist/a11y/tests/keyboardMode.test.js +27 -0
- package/dist/a11y/types.d.ts +24 -0
- package/dist/a11y/types.js +1 -0
- package/dist/constants/keys.d.ts +11 -0
- package/dist/constants/keys.js +11 -0
- package/dist/css/StyleCache.d.ts +7 -0
- package/dist/css/StyleCache.js +19 -0
- package/dist/css/classNames.d.ts +7 -0
- package/dist/css/classNames.js +19 -0
- package/dist/css/index.d.ts +2 -0
- package/dist/css/index.js +4 -0
- package/dist/css/tests/StyleCache.test.d.ts +1 -0
- package/dist/css/tests/StyleCache.test.js +45 -0
- package/dist/css/tests/classNames.test.d.ts +1 -0
- package/dist/css/tests/classNames.test.js +63 -0
- package/dist/dom/findClosestScrollableContainer.d.ts +5 -0
- package/dist/dom/findClosestScrollableContainer.js +12 -0
- package/dist/dom/findParent.d.ts +2 -0
- package/dist/dom/findParent.js +10 -0
- package/dist/dom/index.d.ts +3 -0
- package/dist/dom/index.js +4 -0
- package/dist/dom/tests/findClosestScrollableContainer.test.d.ts +1 -0
- package/dist/dom/tests/findClosestScrollableContainer.test.js +61 -0
- package/dist/dom/tests/findParent.test.d.ts +1 -0
- package/dist/dom/tests/findParent.test.js +45 -0
- package/dist/flyout/Flyout.d.ts +2 -2
- package/dist/flyout/Flyout.js +6 -6
- package/dist/flyout/index.d.ts +1 -1
- package/dist/flyout/index.js +1 -1
- package/dist/flyout/tests/Flyout.test.js +9 -9
- package/dist/flyout/types.d.ts +2 -2
- package/dist/flyout/utilities/applyPosition.js +1 -1
- package/dist/flyout/utilities/tests/applyPosition.test.js +10 -10
- package/dist/flyout/utilities/tests/calculateLayoutAdjustment.test.js +2 -2
- package/dist/flyout/utilities/tests/calculatePosition.test.js +1 -1
- package/dist/flyout/utilities/tests/centerBySize.test.js +1 -1
- package/dist/flyout/utilities/tests/getPositionFallbacks.test.js +1 -1
- package/dist/flyout/utilities/tests/getRTLPosition.test.js +1 -1
- package/dist/flyout/utilities/tests/isFullyVisible.test.js +1 -1
- package/dist/helpers/classNames.d.ts +7 -0
- package/dist/helpers/classNames.js +19 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/tests/classNames.test.d.ts +1 -0
- package/dist/helpers/tests/classNames.test.js +63 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +2 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/internal.d.ts +11 -0
- package/dist/internal.js +10 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +16 -0
- package/dist/scroll/disable.d.ts +7 -0
- package/dist/scroll/disable.js +15 -0
- package/dist/scroll/helpers.d.ts +1 -0
- package/dist/scroll/helpers.js +17 -0
- package/dist/scroll/index.d.ts +2 -0
- package/dist/scroll/index.js +4 -0
- package/dist/scroll/lock.d.ts +7 -0
- package/dist/scroll/lock.js +26 -0
- package/dist/scroll/lockSafari.d.ts +2 -0
- package/dist/scroll/lockSafari.js +20 -0
- package/dist/scroll/lockStandard.d.ts +4 -0
- package/dist/scroll/lockStandard.js +15 -0
- package/dist/scroll/tests/lock.test.d.ts +1 -0
- package/dist/scroll/tests/lock.test.js +81 -0
- package/package.json +6 -1
- package/dist/flyout/utilities/findClosestFixedContainer.d.ts +0 -5
- package/dist/flyout/utilities/findClosestFixedContainer.js +0 -18
- package/dist/flyout/utilities/tests/findClosestFixedContainer.test.js +0 -46
- /package/dist/{flyout/utilities/tests/findClosestFixedContainer.test.d.ts → a11y/tests/Chain.test.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { expect, test, describe, beforeEach, vi, afterEach } from "vitest";
|
|
2
|
+
import { lockScroll } from "../lock.js";
|
|
3
|
+
// Mock the platform module to avoid iOS path
|
|
4
|
+
vi.mock("@/platform", () => ({
|
|
5
|
+
isIOS: () => false,
|
|
6
|
+
}));
|
|
7
|
+
describe("scroll/lockScroll", () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// Reset the body styles before each test
|
|
10
|
+
document.body.style.overflow = "";
|
|
11
|
+
document.body.style.paddingRight = "";
|
|
12
|
+
document.body.innerHTML = "";
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
// Clean up
|
|
16
|
+
document.body.style.overflow = "";
|
|
17
|
+
document.body.style.paddingRight = "";
|
|
18
|
+
document.body.innerHTML = "";
|
|
19
|
+
});
|
|
20
|
+
test("locks scroll on body", () => {
|
|
21
|
+
const unlock = lockScroll({});
|
|
22
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
23
|
+
unlock?.();
|
|
24
|
+
expect(document.body.style.overflow).toBe("");
|
|
25
|
+
});
|
|
26
|
+
test("locks scroll on custom container element", () => {
|
|
27
|
+
const container = document.createElement("div");
|
|
28
|
+
container.style.overflow = "auto";
|
|
29
|
+
container.style.height = "200px";
|
|
30
|
+
document.body.appendChild(container);
|
|
31
|
+
const unlock = lockScroll({ containerEl: container });
|
|
32
|
+
expect(container.style.overflow).toBe("hidden");
|
|
33
|
+
expect(document.body.style.overflow).not.toBe("hidden");
|
|
34
|
+
unlock?.();
|
|
35
|
+
expect(container.style.overflow).toBe("auto");
|
|
36
|
+
});
|
|
37
|
+
test("finds scrollable container from origin element", () => {
|
|
38
|
+
const scrollableContainer = document.createElement("div");
|
|
39
|
+
scrollableContainer.style.overflow = "auto";
|
|
40
|
+
scrollableContainer.style.height = "200px";
|
|
41
|
+
document.body.appendChild(scrollableContainer);
|
|
42
|
+
// Add content to make it scrollable
|
|
43
|
+
const content = document.createElement("div");
|
|
44
|
+
content.style.height = "500px";
|
|
45
|
+
scrollableContainer.appendChild(content);
|
|
46
|
+
const originEl = document.createElement("div");
|
|
47
|
+
scrollableContainer.appendChild(originEl);
|
|
48
|
+
const unlock = lockScroll({ originEl });
|
|
49
|
+
expect(scrollableContainer.style.overflow).toBe("hidden");
|
|
50
|
+
unlock?.();
|
|
51
|
+
expect(scrollableContainer.style.overflow).toBe("auto");
|
|
52
|
+
});
|
|
53
|
+
test("unlocks after multiple locks", () => {
|
|
54
|
+
const unlock1 = lockScroll({});
|
|
55
|
+
const unlock2 = lockScroll({});
|
|
56
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
57
|
+
unlock1?.();
|
|
58
|
+
expect(document.body.style.overflow).toBe("");
|
|
59
|
+
unlock2?.();
|
|
60
|
+
expect(document.body.style.overflow).toBe("");
|
|
61
|
+
});
|
|
62
|
+
test("calls lock callback immediately", () => {
|
|
63
|
+
const lockCb = vi.fn();
|
|
64
|
+
lockScroll({ callback: lockCb });
|
|
65
|
+
expect(lockCb).toHaveBeenCalledTimes(1);
|
|
66
|
+
});
|
|
67
|
+
test("calls unlock callback when unlocking", () => {
|
|
68
|
+
const unlockCb = vi.fn();
|
|
69
|
+
const unlock = lockScroll({});
|
|
70
|
+
unlock?.({ callback: unlockCb });
|
|
71
|
+
expect(unlockCb).toHaveBeenCalledTimes(1);
|
|
72
|
+
});
|
|
73
|
+
test("handles origin element when no scrollable container is found (falls back to body)", () => {
|
|
74
|
+
const originEl = document.createElement("div");
|
|
75
|
+
document.body.appendChild(originEl);
|
|
76
|
+
const unlock = lockScroll({ originEl });
|
|
77
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
78
|
+
unlock?.();
|
|
79
|
+
expect(document.body.style.overflow).toBe("");
|
|
80
|
+
});
|
|
81
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reshaped/utilities",
|
|
3
3
|
"description": "Vanilla JS utilities for implementing common UI patterns",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.10.0-canary.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://reshaped.so",
|
|
7
7
|
"repository": {
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
"import": "./dist/index.js",
|
|
28
28
|
"default": "./dist/index.js"
|
|
29
29
|
},
|
|
30
|
+
"./internal": {
|
|
31
|
+
"types": "./dist/internal.d.ts",
|
|
32
|
+
"import": "./dist/internal.js",
|
|
33
|
+
"default": "./dist/internal.js"
|
|
34
|
+
},
|
|
30
35
|
"./package.json": "./package.json"
|
|
31
36
|
},
|
|
32
37
|
"peerDependencies": {
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import getShadowRoot from "../../dom/getShadowRoot.js";
|
|
2
|
-
const findClosestPositionContainer = (args) => {
|
|
3
|
-
const { el, iteration = 0 } = args;
|
|
4
|
-
const style = el && window.getComputedStyle(el);
|
|
5
|
-
const position = style?.position;
|
|
6
|
-
const isFixed = position === "fixed" || position === "sticky";
|
|
7
|
-
if (iteration === 0) {
|
|
8
|
-
const shadowRoot = getShadowRoot(el);
|
|
9
|
-
if (shadowRoot?.firstElementChild)
|
|
10
|
-
return shadowRoot.firstElementChild;
|
|
11
|
-
}
|
|
12
|
-
if (el === document.body || !el)
|
|
13
|
-
return document.body;
|
|
14
|
-
if (isFixed)
|
|
15
|
-
return el;
|
|
16
|
-
return findClosestPositionContainer({ el: el.parentElement, iteration: iteration + 1 });
|
|
17
|
-
};
|
|
18
|
-
export default (args) => findClosestPositionContainer({ ...args, iteration: 0 });
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe } from "vitest";
|
|
2
|
-
import findClosestFixedContainer from "flyout/utilities/findClosestFixedContainer";
|
|
3
|
-
describe("flyout/findClosestFixedContainer", () => {
|
|
4
|
-
test("returns document.body when element is null", () => {
|
|
5
|
-
const result = findClosestFixedContainer({ el: null });
|
|
6
|
-
expect(result).toBe(document.body);
|
|
7
|
-
});
|
|
8
|
-
test("returns document.body when element is document.body", () => {
|
|
9
|
-
const result = findClosestFixedContainer({ el: document.body });
|
|
10
|
-
expect(result).toBe(document.body);
|
|
11
|
-
});
|
|
12
|
-
test("returns the element itself when it has position fixed", () => {
|
|
13
|
-
const fixedEl = document.createElement("div");
|
|
14
|
-
fixedEl.style.position = "fixed";
|
|
15
|
-
document.body.appendChild(fixedEl);
|
|
16
|
-
const result = findClosestFixedContainer({ el: fixedEl });
|
|
17
|
-
expect(result).toBe(fixedEl);
|
|
18
|
-
});
|
|
19
|
-
test("returns the element itself when it has position sticky", () => {
|
|
20
|
-
const stickyEl = document.createElement("div");
|
|
21
|
-
stickyEl.style.position = "sticky";
|
|
22
|
-
document.body.appendChild(stickyEl);
|
|
23
|
-
const result = findClosestFixedContainer({ el: stickyEl });
|
|
24
|
-
expect(result).toBe(stickyEl);
|
|
25
|
-
});
|
|
26
|
-
test("returns grandparent when it has position fixed", () => {
|
|
27
|
-
const fixedEl = document.createElement("div");
|
|
28
|
-
fixedEl.style.position = "fixed";
|
|
29
|
-
const childEl = document.createElement("div");
|
|
30
|
-
const grandChildEl = document.createElement("div");
|
|
31
|
-
childEl.appendChild(grandChildEl);
|
|
32
|
-
fixedEl.appendChild(childEl);
|
|
33
|
-
document.body.appendChild(fixedEl);
|
|
34
|
-
const result = findClosestFixedContainer({ el: grandChildEl });
|
|
35
|
-
expect(result).toBe(fixedEl);
|
|
36
|
-
});
|
|
37
|
-
test("returns document.body when no fixed container is found", () => {
|
|
38
|
-
const staticEl = document.createElement("div");
|
|
39
|
-
staticEl.style.position = "static";
|
|
40
|
-
const childEl = document.createElement("div");
|
|
41
|
-
staticEl.appendChild(childEl);
|
|
42
|
-
document.body.appendChild(staticEl);
|
|
43
|
-
const result = findClosestFixedContainer({ el: childEl });
|
|
44
|
-
expect(result).toBe(document.body);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
File without changes
|