@multiplatform.one/components 7.49.0 → 7.49.2
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/dist/cjs/SheetModal/index.cjs +2 -74
- package/dist/cjs/SheetModal/useSheetFrameFocus.cjs +101 -0
- package/dist/cjs/SheetModal/useSheetFrameFocus.native.js +109 -0
- package/dist/cjs/SheetModal/useSheetFrameFocus.native.js.map +1 -0
- package/dist/cjs/componentColors.cjs +3 -1
- package/dist/cjs/componentColors.native.js +3 -1
- package/dist/cjs/componentColors.native.js.map +1 -1
- package/dist/cjs/layouts/page.cjs +1 -1
- package/dist/cjs/layouts/page.native.js +1 -1
- package/dist/cjs/layouts/page.native.js.map +1 -1
- package/dist/cjs/shared/restoreRetries.cjs +96 -0
- package/dist/cjs/shared/restoreRetries.native.js +101 -0
- package/dist/cjs/shared/restoreRetries.native.js.map +1 -0
- package/dist/cjs/shared/useReturnFocusOnClose.cjs +5 -3
- package/dist/cjs/shared/useReturnFocusOnClose.native.js +5 -5
- package/dist/cjs/shared/useReturnFocusOnClose.native.js.map +1 -1
- package/dist/esm/SheetModal/index.mjs +2 -74
- package/dist/esm/SheetModal/index.mjs.map +1 -1
- package/dist/esm/SheetModal/useSheetFrameFocus.mjs +76 -0
- package/dist/esm/SheetModal/useSheetFrameFocus.mjs.map +1 -0
- package/dist/esm/SheetModal/useSheetFrameFocus.native.js +81 -0
- package/dist/esm/SheetModal/useSheetFrameFocus.native.js.map +1 -0
- package/dist/esm/componentColors.mjs +3 -1
- package/dist/esm/componentColors.mjs.map +1 -1
- package/dist/esm/componentColors.native.js +3 -1
- package/dist/esm/componentColors.native.js.map +1 -1
- package/dist/esm/layouts/page.mjs +1 -1
- package/dist/esm/layouts/page.mjs.map +1 -1
- package/dist/esm/layouts/page.native.js +1 -1
- package/dist/esm/layouts/page.native.js.map +1 -1
- package/dist/esm/shared/restoreRetries.mjs +71 -0
- package/dist/esm/shared/restoreRetries.mjs.map +1 -0
- package/dist/esm/shared/restoreRetries.native.js +73 -0
- package/dist/esm/shared/restoreRetries.native.js.map +1 -0
- package/dist/esm/shared/useReturnFocusOnClose.mjs +5 -3
- package/dist/esm/shared/useReturnFocusOnClose.mjs.map +1 -1
- package/dist/esm/shared/useReturnFocusOnClose.native.js +5 -5
- package/dist/esm/shared/useReturnFocusOnClose.native.js.map +1 -1
- package/dist/jsx/SheetModal/index.mjs +2 -74
- package/dist/jsx/SheetModal/index.mjs.map +1 -1
- package/dist/jsx/SheetModal/useSheetFrameFocus.mjs +76 -0
- package/dist/jsx/SheetModal/useSheetFrameFocus.mjs.map +1 -0
- package/dist/jsx/SheetModal/useSheetFrameFocus.native.js +109 -0
- package/dist/jsx/SheetModal/useSheetFrameFocus.native.js.map +1 -0
- package/dist/jsx/componentColors.mjs +3 -1
- package/dist/jsx/componentColors.mjs.map +1 -1
- package/dist/jsx/componentColors.native.js +3 -1
- package/dist/jsx/componentColors.native.js.map +1 -1
- package/dist/jsx/layouts/page.mjs +1 -1
- package/dist/jsx/layouts/page.mjs.map +1 -1
- package/dist/jsx/layouts/page.native.js +1 -1
- package/dist/jsx/layouts/page.native.js.map +1 -1
- package/dist/jsx/shared/restoreRetries.mjs +71 -0
- package/dist/jsx/shared/restoreRetries.mjs.map +1 -0
- package/dist/jsx/shared/restoreRetries.native.js +101 -0
- package/dist/jsx/shared/restoreRetries.native.js.map +1 -0
- package/dist/jsx/shared/useReturnFocusOnClose.mjs +5 -3
- package/dist/jsx/shared/useReturnFocusOnClose.mjs.map +1 -1
- package/dist/jsx/shared/useReturnFocusOnClose.native.js +5 -5
- package/dist/jsx/shared/useReturnFocusOnClose.native.js.map +1 -1
- package/package.json +9 -9
- package/src/SheetModal/index.tsx +3 -84
- package/src/SheetModal/useSheetFrameFocus.spec.tsx +72 -0
- package/src/SheetModal/useSheetFrameFocus.ts +88 -0
- package/src/componentColors.ts +11 -2
- package/src/export-surface.spec.tsx +3 -1
- package/src/layouts/PageSection.stories.tsx +2 -2
- package/src/layouts/page.tsx +5 -2
- package/src/shared/restoreRetries.ts +87 -0
- package/src/shared/useReturnFocusOnClose.spec.tsx +51 -2
- package/src/shared/useReturnFocusOnClose.ts +8 -6
- package/types/SheetModal/index.d.ts.map +1 -1
- package/types/SheetModal/useSheetFrameFocus.d.ts +7 -0
- package/types/SheetModal/useSheetFrameFocus.d.ts.map +1 -0
- package/types/componentColors.d.ts +6 -2
- package/types/componentColors.d.ts.map +1 -1
- package/types/layouts/page.d.ts +4 -1
- package/types/layouts/page.d.ts.map +1 -1
- package/types/shared/restoreRetries.d.ts +14 -0
- package/types/shared/restoreRetries.d.ts.map +1 -0
- package/types/shared/useReturnFocusOnClose.d.ts.map +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SheetModal's web focus: move focus into the frame on open, trap Tab while
|
|
3
|
+
* open, return dropped focus on close (Radix Dialog anatomy, see ./index.tsx).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { wasKeyboardFocus } from "@multiplatform.one/theme";
|
|
7
|
+
import { useEffect, useRef, type RefObject } from "react";
|
|
8
|
+
import { isWeb } from "tamagui";
|
|
9
|
+
import { useRestoreRetries } from "../shared/restoreRetries";
|
|
10
|
+
|
|
11
|
+
const FOCUSABLE =
|
|
12
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
13
|
+
|
|
14
|
+
export function useSheetFrameFocus(open: boolean, frameRef: RefObject<HTMLElement | null>) {
|
|
15
|
+
const prevRef = useRef<HTMLElement | null>(null);
|
|
16
|
+
const wasOpenRef = useRef(false);
|
|
17
|
+
if (isWeb && typeof document !== "undefined") {
|
|
18
|
+
if (open && !wasOpenRef.current) {
|
|
19
|
+
prevRef.current = document.activeElement as HTMLElement | null;
|
|
20
|
+
}
|
|
21
|
+
wasOpenRef.current = open;
|
|
22
|
+
}
|
|
23
|
+
const retries = useRestoreRetries();
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!isWeb || typeof document === "undefined" || !open) return;
|
|
27
|
+
retries.cancel();
|
|
28
|
+
const frame = frameRef.current;
|
|
29
|
+
const restore = () => {
|
|
30
|
+
if (typeof document === "undefined") return;
|
|
31
|
+
const target = prevRef.current;
|
|
32
|
+
if (!target || !target.isConnected) return;
|
|
33
|
+
const ae = document.activeElement;
|
|
34
|
+
const dropped =
|
|
35
|
+
!ae ||
|
|
36
|
+
ae === document.body ||
|
|
37
|
+
ae === document.documentElement ||
|
|
38
|
+
!!frameRef.current?.contains(ae);
|
|
39
|
+
if (dropped) {
|
|
40
|
+
target.focus({
|
|
41
|
+
preventScroll: true,
|
|
42
|
+
focusVisible: wasKeyboardFocus(),
|
|
43
|
+
} as FocusOptions);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const restoreLater = () => retries.schedule(restore, 320);
|
|
47
|
+
if (!frame || typeof frame.addEventListener !== "function") return restoreLater;
|
|
48
|
+
|
|
49
|
+
const focusIn = () => {
|
|
50
|
+
if (typeof document === "undefined") return;
|
|
51
|
+
if (frame.contains(document.activeElement)) return;
|
|
52
|
+
const first = frame.querySelector<HTMLElement>(FOCUSABLE);
|
|
53
|
+
(first ?? frame).focus({ preventScroll: true, focusVisible: false } as FocusOptions);
|
|
54
|
+
};
|
|
55
|
+
let innerRaf = 0;
|
|
56
|
+
const raf = requestAnimationFrame(() => {
|
|
57
|
+
innerRaf = requestAnimationFrame(focusIn);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
61
|
+
if (e.key !== "Tab") return;
|
|
62
|
+
const focusables = Array.from(frame.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
|
|
63
|
+
(el) => el.offsetWidth > 0 || el.offsetHeight > 0,
|
|
64
|
+
);
|
|
65
|
+
if (!focusables.length) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const first = focusables[0];
|
|
70
|
+
const last = focusables[focusables.length - 1];
|
|
71
|
+
const current = document.activeElement;
|
|
72
|
+
if (e.shiftKey && (current === first || current === frame)) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
last.focus();
|
|
75
|
+
} else if (!e.shiftKey && current === last) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
first.focus();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
frame.addEventListener("keydown", onKeyDown);
|
|
81
|
+
return () => {
|
|
82
|
+
cancelAnimationFrame(raf);
|
|
83
|
+
cancelAnimationFrame(innerRaf);
|
|
84
|
+
frame.removeEventListener("keydown", onKeyDown);
|
|
85
|
+
restoreLater();
|
|
86
|
+
};
|
|
87
|
+
}, [open, frameRef, retries]);
|
|
88
|
+
}
|
package/src/componentColors.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isWeb } from "@multiplatform.one/platform";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Semantic color ramp constants for non-form components.
|
|
3
5
|
*
|
|
@@ -122,8 +124,15 @@ export const componentColors = {
|
|
|
122
124
|
} as const;
|
|
123
125
|
|
|
124
126
|
/**
|
|
125
|
-
*
|
|
127
|
+
* The prominent section heading (LC-156): one step below the page title, in
|
|
128
|
+
* the primary ink, with no rule under it. $6 on web (18 px over a 15 px body)
|
|
129
|
+
* and $5 on native (20 pt over a 17 pt body) hold the same section-to-body
|
|
130
|
+
* ratio on both ladders, because the native ladder runs a step larger.
|
|
126
131
|
* Requires a size variant: H1-H6, Heading, SizableText, Paragraph or Dialog.Title.
|
|
127
132
|
* Spread before the knob's heading family so headingFont reaches the node.
|
|
128
133
|
*/
|
|
129
|
-
export const sectionHeading = {
|
|
134
|
+
export const sectionHeading = {
|
|
135
|
+
fontFamily: "$heading",
|
|
136
|
+
size: isWeb ? "$6" : "$5",
|
|
137
|
+
color: "$color12",
|
|
138
|
+
} as const;
|
|
@@ -113,10 +113,12 @@ describe("semantic colour layer is importable by a stable name", () => {
|
|
|
113
113
|
expect(pkg.sectionHeading).toBe(sectionHeading);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
it("pins sectionHeading to $heading
|
|
116
|
+
it("pins sectionHeading to the prominent step: $heading, primary ink, $6 on web (LC-156)", () => {
|
|
117
|
+
// jsdom runs the web branch; native resolves $5 (20 pt over its 17 pt body).
|
|
117
118
|
expect(sectionHeading).toEqual({
|
|
118
119
|
fontFamily: "$heading",
|
|
119
120
|
size: "$6",
|
|
121
|
+
color: "$color12",
|
|
120
122
|
});
|
|
121
123
|
});
|
|
122
124
|
|
|
@@ -11,7 +11,7 @@ const meta: Meta<typeof PageSection> = {
|
|
|
11
11
|
docs: {
|
|
12
12
|
description: {
|
|
13
13
|
component:
|
|
14
|
-
"Labeled content section: H2 title, optional description, divider, and optional soft card surface. Title size is the shared sectionHeading scale; weight takes the heading table at regular and 700 at bold. Surfaced sections do not wrap Tint (R12).",
|
|
14
|
+
"Labeled content section: H2 title, optional description, optional divider (off by default, LC-156), and optional soft card surface. Title size is the shared sectionHeading scale; weight takes the heading table at regular and 700 at bold. Surfaced sections do not wrap Tint (R12).",
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
},
|
|
@@ -24,7 +24,7 @@ const meta: Meta<typeof PageSection> = {
|
|
|
24
24
|
args: {
|
|
25
25
|
title: "Section title",
|
|
26
26
|
description: "Short description of what lives in this section",
|
|
27
|
-
divider:
|
|
27
|
+
divider: false,
|
|
28
28
|
surface: false,
|
|
29
29
|
},
|
|
30
30
|
};
|
package/src/layouts/page.tsx
CHANGED
|
@@ -326,7 +326,10 @@ export interface PageSectionProps extends YStackProps {
|
|
|
326
326
|
description?: string;
|
|
327
327
|
/** Override the default H2. */
|
|
328
328
|
heading?: ReactNode;
|
|
329
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Draw a rule under the title row. Default: false (LC-156): a section is
|
|
331
|
+
* grouped by its heading and the section gap, not by a line.
|
|
332
|
+
*/
|
|
330
333
|
divider?: boolean;
|
|
331
334
|
/** Wrap content in a soft card surface. Default: false. */
|
|
332
335
|
surface?: boolean;
|
|
@@ -346,7 +349,7 @@ export function PageSection({
|
|
|
346
349
|
title,
|
|
347
350
|
description,
|
|
348
351
|
heading,
|
|
349
|
-
divider =
|
|
352
|
+
divider = false,
|
|
350
353
|
surface = false,
|
|
351
354
|
headingLevel = 2,
|
|
352
355
|
children,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The retries an overlay runs to return focus after it closes: after two
|
|
3
|
+
* frames, then after the exit window (FZ-7904). The handles are kept, so a
|
|
4
|
+
* new schedule or a reopen cancels the old retries instead of stacking them,
|
|
5
|
+
* and an unmount leaves no frame or timer behind: the restore it would have
|
|
6
|
+
* run happens once, in a microtask, unless the component mounted again
|
|
7
|
+
* (StrictMode's simulated unmount). Mirror of the forms-package helper.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useEffect, useRef } from "react";
|
|
11
|
+
|
|
12
|
+
export interface RestoreRetries {
|
|
13
|
+
schedule: (restore: () => void, delayMs: number) => void;
|
|
14
|
+
cancel: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const hasFrames = () => typeof requestAnimationFrame === "function";
|
|
18
|
+
|
|
19
|
+
export function useRestoreRetries(): RestoreRetries {
|
|
20
|
+
const mountedRef = useRef(false);
|
|
21
|
+
const retriesRef = useRef<(RestoreRetries & { unmount: () => void }) | null>(null);
|
|
22
|
+
if (!retriesRef.current) {
|
|
23
|
+
let outer = 0;
|
|
24
|
+
let inner = 0;
|
|
25
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
26
|
+
let pending: (() => void) | null = null;
|
|
27
|
+
const restoreOnceUnmounted = (restore: () => void) => {
|
|
28
|
+
queueMicrotask(() => {
|
|
29
|
+
if (!mountedRef.current) restore();
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const cancel = () => {
|
|
33
|
+
if (typeof cancelAnimationFrame === "function") {
|
|
34
|
+
if (outer) cancelAnimationFrame(outer);
|
|
35
|
+
if (inner) cancelAnimationFrame(inner);
|
|
36
|
+
}
|
|
37
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
38
|
+
outer = 0;
|
|
39
|
+
inner = 0;
|
|
40
|
+
timer = undefined;
|
|
41
|
+
pending = null;
|
|
42
|
+
};
|
|
43
|
+
retriesRef.current = {
|
|
44
|
+
cancel,
|
|
45
|
+
schedule(restore, delayMs) {
|
|
46
|
+
cancel();
|
|
47
|
+
if (!mountedRef.current) {
|
|
48
|
+
restoreOnceUnmounted(restore);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
pending = restore;
|
|
52
|
+
if (hasFrames()) {
|
|
53
|
+
outer = requestAnimationFrame(() => {
|
|
54
|
+
outer = 0;
|
|
55
|
+
// The outer frame can outlive the document (a test window torn
|
|
56
|
+
// down between the two frames), and with it the global.
|
|
57
|
+
if (!hasFrames()) return;
|
|
58
|
+
inner = requestAnimationFrame(() => {
|
|
59
|
+
inner = 0;
|
|
60
|
+
if (timer === undefined) pending = null;
|
|
61
|
+
restore();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
timer = setTimeout(() => {
|
|
66
|
+
timer = undefined;
|
|
67
|
+
if (!outer && !inner) pending = null;
|
|
68
|
+
restore();
|
|
69
|
+
}, delayMs);
|
|
70
|
+
},
|
|
71
|
+
unmount() {
|
|
72
|
+
const restore = pending;
|
|
73
|
+
cancel();
|
|
74
|
+
if (restore) restoreOnceUnmounted(restore);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const retries = retriesRef.current;
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
mountedRef.current = true;
|
|
81
|
+
return () => {
|
|
82
|
+
mountedRef.current = false;
|
|
83
|
+
retries.unmount();
|
|
84
|
+
};
|
|
85
|
+
}, [retries]);
|
|
86
|
+
return retries;
|
|
87
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { act, cleanup, renderHook } from "@testing-library/react";
|
|
2
|
+
import { StrictMode } from "react";
|
|
2
3
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { holdAnimationFrames } from "@multiplatform.one/test-utils/frames";
|
|
3
5
|
import { useReturnFocusOnClose } from "./useReturnFocusOnClose";
|
|
4
6
|
|
|
5
7
|
afterEach(() => {
|
|
@@ -10,15 +12,16 @@ afterEach(() => {
|
|
|
10
12
|
});
|
|
11
13
|
|
|
12
14
|
describe("useReturnFocusOnClose", () => {
|
|
13
|
-
function setup() {
|
|
15
|
+
function setup({ holdFrames = false } = {}) {
|
|
14
16
|
vi.useFakeTimers();
|
|
17
|
+
const frames = holdFrames ? holdAnimationFrames() : null;
|
|
15
18
|
const trigger = document.createElement("button");
|
|
16
19
|
document.body.append(trigger);
|
|
17
20
|
trigger.focus();
|
|
18
21
|
const hook = renderHook(({ open }) => useReturnFocusOnClose(open), {
|
|
19
22
|
initialProps: { open: true },
|
|
20
23
|
});
|
|
21
|
-
return { ...hook, trigger };
|
|
24
|
+
return { ...hook, frames, trigger };
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
it("restores dropped focus after the close animation", async () => {
|
|
@@ -36,4 +39,50 @@ describe("useReturnFocusOnClose", () => {
|
|
|
36
39
|
vi.stubGlobal("document", undefined);
|
|
37
40
|
expect(() => vi.advanceTimersByTime(400)).not.toThrow();
|
|
38
41
|
});
|
|
42
|
+
|
|
43
|
+
// FZ-7904: the close retries used to drop their frame and timer ids. These
|
|
44
|
+
// unmount before the outer afterEach drops the held frames.
|
|
45
|
+
describe("frame handles", () => {
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
cleanup();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("a StrictMode remount on open does not restore", async () => {
|
|
51
|
+
vi.useFakeTimers();
|
|
52
|
+
const trigger = document.createElement("button");
|
|
53
|
+
document.body.append(trigger);
|
|
54
|
+
trigger.focus();
|
|
55
|
+
renderHook(() => useReturnFocusOnClose(true), { wrapper: StrictMode });
|
|
56
|
+
trigger.blur();
|
|
57
|
+
await Promise.resolve();
|
|
58
|
+
await act(() => vi.advanceTimersByTimeAsync(400));
|
|
59
|
+
expect(document.activeElement).toBe(document.body);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("cancels a close's retries when the overlay reopens", () => {
|
|
63
|
+
const h = setup({ holdFrames: true });
|
|
64
|
+
h.rerender({ open: false });
|
|
65
|
+
h.rerender({ open: true });
|
|
66
|
+
expect(h.frames!.pending).toBe(0);
|
|
67
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("leaves no frame or timer behind once it unmounts, and still restores", async () => {
|
|
71
|
+
const h = setup({ holdFrames: true });
|
|
72
|
+
h.trigger.blur();
|
|
73
|
+
h.rerender({ open: false });
|
|
74
|
+
h.unmount();
|
|
75
|
+
expect(h.frames!.pending).toBe(0);
|
|
76
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
77
|
+
await Promise.resolve();
|
|
78
|
+
expect(document.activeElement).toBe(h.trigger);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("does not throw when its frame outlives the requestAnimationFrame global", () => {
|
|
82
|
+
const h = setup({ holdFrames: true });
|
|
83
|
+
h.rerender({ open: false });
|
|
84
|
+
vi.stubGlobal("requestAnimationFrame", undefined);
|
|
85
|
+
expect(() => h.frames!.flush()).not.toThrow();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
39
88
|
});
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { useEffect, useRef } from "react";
|
|
19
19
|
import { isWeb } from "tamagui";
|
|
20
20
|
import { wasKeyboardFocus } from "@multiplatform.one/theme";
|
|
21
|
+
import { useRestoreRetries } from "./restoreRetries";
|
|
21
22
|
|
|
22
23
|
const canUseDom = () => isWeb && typeof document !== "undefined";
|
|
23
24
|
|
|
@@ -35,13 +36,15 @@ export function useReturnFocusOnClose(open: boolean) {
|
|
|
35
36
|
}
|
|
36
37
|
wasOpenRef.current = open;
|
|
37
38
|
}
|
|
39
|
+
const retries = useRestoreRetries();
|
|
38
40
|
useEffect(() => {
|
|
39
41
|
if (!canUseDom() || !open) return;
|
|
42
|
+
retries.cancel();
|
|
40
43
|
return () => {
|
|
41
44
|
const restore = () => {
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
+
// The microtask after an unmount can run once the document is gone
|
|
46
|
+
// (a test environment torn down), and `isConnected` stays true on
|
|
47
|
+
// the detached node.
|
|
45
48
|
if (!canUseDom()) return;
|
|
46
49
|
const target = prevRef.current;
|
|
47
50
|
if (!target || !target.isConnected) return;
|
|
@@ -54,8 +57,7 @@ export function useReturnFocusOnClose(open: boolean) {
|
|
|
54
57
|
};
|
|
55
58
|
// Exit animations unmount the overlay a few frames later; retry after
|
|
56
59
|
// the typical exit window. Both calls are idempotent.
|
|
57
|
-
|
|
58
|
-
setTimeout(restore, 320);
|
|
60
|
+
retries.schedule(restore, 320);
|
|
59
61
|
};
|
|
60
|
-
}, [open]);
|
|
62
|
+
}, [open, retries]);
|
|
61
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SheetModal/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAA4B,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SheetModal/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKjE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uEAAuE;IACvE,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAkCD,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,SAAc,EACd,UAAU,EACV,IAAY,GACb,EAAE,eAAe,2CAkFjB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SheetModal's web focus: move focus into the frame on open, trap Tab while
|
|
3
|
+
* open, return dropped focus on close (Radix Dialog anatomy, see ./index.tsx).
|
|
4
|
+
*/
|
|
5
|
+
import { type RefObject } from "react";
|
|
6
|
+
export declare function useSheetFrameFocus(open: boolean, frameRef: RefObject<HTMLElement | null>): void;
|
|
7
|
+
//# sourceMappingURL=useSheetFrameFocus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSheetFrameFocus.d.ts","sourceRoot":"","sources":["../../src/SheetModal/useSheetFrameFocus.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAO1D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,QA0ExF"}
|
|
@@ -102,12 +102,16 @@ export declare const componentColors: {
|
|
|
102
102
|
readonly debug: "$color9";
|
|
103
103
|
};
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* The prominent section heading (LC-156): one step below the page title, in
|
|
106
|
+
* the primary ink, with no rule under it. $6 on web (18 px over a 15 px body)
|
|
107
|
+
* and $5 on native (20 pt over a 17 pt body) hold the same section-to-body
|
|
108
|
+
* ratio on both ladders, because the native ladder runs a step larger.
|
|
106
109
|
* Requires a size variant: H1-H6, Heading, SizableText, Paragraph or Dialog.Title.
|
|
107
110
|
* Spread before the knob's heading family so headingFont reaches the node.
|
|
108
111
|
*/
|
|
109
112
|
export declare const sectionHeading: {
|
|
110
113
|
readonly fontFamily: "$heading";
|
|
111
|
-
readonly size: "$6";
|
|
114
|
+
readonly size: "$5" | "$6";
|
|
115
|
+
readonly color: "$color12";
|
|
112
116
|
};
|
|
113
117
|
//# sourceMappingURL=componentColors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentColors.d.ts","sourceRoot":"","sources":["../src/componentColors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"componentColors.d.ts","sourceRoot":"","sources":["../src/componentColors.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,eAAO,MAAM,eAAe;IAC1B;;;;;;;;OAQG;;;;;IAMH,yEAAyE;;;;;;;IAQzE;;;;;OAKG;;;;;;;;IASH,yBAAyB;;;;;IAczB,yBAAyB;;;;;;;;IASzB;;;;;;;;;;OAUG;;;;;;;;IASH,4BAA4B;;;;;;IAO5B;;2EAEuE;;;;;;;;IASvE;;;+EAG2E;;;;;;IAO3E,+BAA+B;;IAG/B,4BAA4B;;CAEpB,CAAC;AAEX;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;CAIjB,CAAC"}
|
package/types/layouts/page.d.ts
CHANGED
|
@@ -104,7 +104,10 @@ export interface PageSectionProps extends YStackProps {
|
|
|
104
104
|
description?: string;
|
|
105
105
|
/** Override the default H2. */
|
|
106
106
|
heading?: ReactNode;
|
|
107
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Draw a rule under the title row. Default: false (LC-156): a section is
|
|
109
|
+
* grouped by its heading and the section gap, not by a line.
|
|
110
|
+
*/
|
|
108
111
|
divider?: boolean;
|
|
109
112
|
/** Wrap content in a soft card surface. Default: false. */
|
|
110
113
|
surface?: boolean;
|
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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The retries an overlay runs to return focus after it closes: after two
|
|
3
|
+
* frames, then after the exit window (FZ-7904). The handles are kept, so a
|
|
4
|
+
* new schedule or a reopen cancels the old retries instead of stacking them,
|
|
5
|
+
* and an unmount leaves no frame or timer behind: the restore it would have
|
|
6
|
+
* run happens once, in a microtask, unless the component mounted again
|
|
7
|
+
* (StrictMode's simulated unmount). Mirror of the forms-package helper.
|
|
8
|
+
*/
|
|
9
|
+
export interface RestoreRetries {
|
|
10
|
+
schedule: (restore: () => void, delayMs: number) => void;
|
|
11
|
+
cancel: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function useRestoreRetries(): RestoreRetries;
|
|
14
|
+
//# sourceMappingURL=restoreRetries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restoreRetries.d.ts","sourceRoot":"","sources":["../../src/shared/restoreRetries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAID,wBAAgB,iBAAiB,IAAI,cAAc,CAoElD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReturnFocusOnClose.d.ts","sourceRoot":"","sources":["../../src/shared/useReturnFocusOnClose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"useReturnFocusOnClose.d.ts","sourceRoot":"","sources":["../../src/shared/useReturnFocusOnClose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAcH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,QAiClD"}
|