@yamada-ui/react 2.3.0-dev-20260730075027 → 2.3.0-dev-20260730080927
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/components/drawer/drawer.cjs +1 -1
- package/dist/cjs/components/focus-lock/focus-lock.cjs +26 -9
- package/dist/cjs/components/focus-lock/focus-lock.cjs.map +1 -1
- package/dist/cjs/components/focus-lock/index.cjs +1 -0
- package/dist/cjs/components/modal/modal.cjs +1 -1
- package/dist/cjs/components/portal/portal.cjs +16 -0
- package/dist/cjs/components/portal/portal.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -1
- package/dist/esm/components/drawer/drawer.js +1 -1
- package/dist/esm/components/focus-lock/focus-lock.js +27 -11
- package/dist/esm/components/focus-lock/focus-lock.js.map +1 -1
- package/dist/esm/components/focus-lock/index.js +2 -2
- package/dist/esm/components/modal/modal.js +1 -1
- package/dist/esm/components/portal/portal.js +17 -1
- package/dist/esm/components/portal/portal.js.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/types/components/chart/cartesian-chart.style.d.ts +1 -1
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/focus-lock/focus-lock.d.ts +2 -1
- package/dist/types/components/focus-lock/index.d.ts +2 -2
- package/dist/types/index.d.ts +3 -3
- package/package.json +2 -2
|
@@ -5,11 +5,11 @@ const require_factory = require("../../core/system/factory.cjs");
|
|
|
5
5
|
const require_create_component = require("../../core/components/create-component.cjs");
|
|
6
6
|
const require_factory$1 = require("../motion/factory.cjs");
|
|
7
7
|
const require_hooks_use_value_index = require("../../hooks/use-value/index.cjs");
|
|
8
|
+
const require_focus_lock = require("../focus-lock/focus-lock.cjs");
|
|
8
9
|
const require_portal = require("../portal/portal.cjs");
|
|
9
10
|
const require_button = require("../button/button.cjs");
|
|
10
11
|
const require_close_button = require("../close-button/close-button.cjs");
|
|
11
12
|
const require_fade = require("../fade/fade.cjs");
|
|
12
|
-
const require_focus_lock = require("../focus-lock/focus-lock.cjs");
|
|
13
13
|
const require_drawer_style = require("./drawer.style.cjs");
|
|
14
14
|
const require_slide = require("../slide/slide.cjs");
|
|
15
15
|
const require_use_drawer = require("./use-drawer.cjs");
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_context = require("../../utils/context.cjs");
|
|
3
4
|
const require_utils_index = require("../../utils/index.cjs");
|
|
4
5
|
let react = require("react");
|
|
5
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
7
|
let react_focus_lock = require("react-focus-lock");
|
|
7
8
|
react_focus_lock = require_runtime.__toESM(react_focus_lock, 1);
|
|
8
9
|
//#region src/components/focus-lock/focus-lock.tsx
|
|
10
|
+
const [FocusLockShardContext, useFocusLockShard] = require_context.createContext({
|
|
11
|
+
name: "FocusLockShardContext",
|
|
12
|
+
strict: false
|
|
13
|
+
});
|
|
9
14
|
const InternalFocusLock = (0, require_utils_index.utils_exports.interopDefault)(react_focus_lock.default);
|
|
10
15
|
/**
|
|
11
16
|
* `FocusLock` is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range.
|
|
@@ -13,7 +18,14 @@ const InternalFocusLock = (0, require_utils_index.utils_exports.interopDefault)(
|
|
|
13
18
|
* @see https://yamada-ui.com/docs/components/focus-lock
|
|
14
19
|
*/
|
|
15
20
|
const FocusLock = ({ autoFocus, children, contentRef, disabled, finalFocusRef, initialFocusRef, lockFocusAcrossFrames, persistentFocus, restoreFocus }) => {
|
|
21
|
+
const [shards, setShards] = (0, react.useState)([]);
|
|
16
22
|
const returnFocus = restoreFocus && !finalFocusRef;
|
|
23
|
+
const registerShard = (0, react.useCallback)((shard) => {
|
|
24
|
+
setShards((prev) => prev.includes(shard) ? prev : [...prev, shard]);
|
|
25
|
+
return () => {
|
|
26
|
+
setShards((prev) => prev.filter((item) => item !== shard));
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
17
29
|
const onActivation = (0, react.useCallback)(() => {
|
|
18
30
|
if (initialFocusRef?.current) initialFocusRef.current.focus();
|
|
19
31
|
else if (contentRef?.current) {
|
|
@@ -25,18 +37,23 @@ const FocusLock = ({ autoFocus, children, contentRef, disabled, finalFocusRef, i
|
|
|
25
37
|
const onDeactivation = (0, react.useCallback)(() => {
|
|
26
38
|
finalFocusRef?.current?.focus();
|
|
27
39
|
}, [finalFocusRef]);
|
|
28
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocusLockShardContext, {
|
|
41
|
+
value: registerShard,
|
|
42
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InternalFocusLock, {
|
|
43
|
+
autoFocus,
|
|
44
|
+
crossFrame: lockFocusAcrossFrames,
|
|
45
|
+
disabled,
|
|
46
|
+
persistentFocus,
|
|
47
|
+
returnFocus,
|
|
48
|
+
shards,
|
|
49
|
+
onActivation,
|
|
50
|
+
onDeactivation,
|
|
51
|
+
children
|
|
52
|
+
})
|
|
37
53
|
});
|
|
38
54
|
};
|
|
39
55
|
//#endregion
|
|
40
56
|
exports.FocusLock = FocusLock;
|
|
57
|
+
exports.useFocusLockShard = useFocusLockShard;
|
|
41
58
|
|
|
42
59
|
//# sourceMappingURL=focus-lock.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-lock.cjs","names":["ReactFocusLock"],"sources":["../../../../src/components/focus-lock/focus-lock.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport { useCallback } from \"react\"\nimport ReactFocusLock from \"react-focus-lock\"\nimport {
|
|
1
|
+
{"version":3,"file":"focus-lock.cjs","names":["createContext","ReactFocusLock"],"sources":["../../../../src/components/focus-lock/focus-lock.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport { useCallback, useState } from \"react\"\nimport ReactFocusLock from \"react-focus-lock\"\nimport {\n createContext,\n getFocusableElements,\n interopDefault,\n} from \"../../utils\"\n\nconst [FocusLockShardContext, useFocusLockShard] = createContext<\n ((shard: HTMLElement) => () => void) | undefined\n>({ name: \"FocusLockShardContext\", strict: false })\n\nexport { useFocusLockShard }\n\nconst InternalFocusLock = interopDefault(ReactFocusLock)\n\nexport interface FocusLockProps extends PropsWithChildren {\n /**\n * If `true`, the first focusable element within the `children` will auto-focused once `FocusLock` mounts.\n *\n * @default false\n */\n autoFocus?: boolean\n /**\n * The `ref` of the wrapper for which the focus-lock wraps.\n */\n contentRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, focus trapping will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * `ref` of the element to return focus to when `FocusLock` unmounts.\n */\n finalFocusRef?: RefObject<HTMLElement | null>\n /**\n * `ref` of the element to receive focus initially.\n */\n initialFocusRef?: RefObject<HTMLElement | null>\n /**\n * Enables aggressive focus capturing within iframes.\n * - If `true`: keep focus in the lock, no matter where lock is active.\n * - If `false`: allows focus to move outside of iframe.\n *\n * @default false\n */\n lockFocusAcrossFrames?: boolean\n /**\n * If `true`, disables text selections inside, and outside focus lock.\n *\n * @default false\n */\n persistentFocus?: boolean\n /**\n * If `true`, focus will be restored to the element that triggered the `FocusLock` once it unmounts.\n *\n * @default false\n */\n restoreFocus?: boolean\n}\n\n/**\n * `FocusLock` is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range.\n *\n * @see https://yamada-ui.com/docs/components/focus-lock\n */\nexport const FocusLock: FC<FocusLockProps> = ({\n autoFocus,\n children,\n contentRef,\n disabled,\n finalFocusRef,\n initialFocusRef,\n lockFocusAcrossFrames,\n persistentFocus,\n restoreFocus,\n}) => {\n const [shards, setShards] = useState<HTMLElement[]>([])\n const returnFocus = restoreFocus && !finalFocusRef\n\n const registerShard = useCallback((shard: HTMLElement) => {\n setShards((prev) => (prev.includes(shard) ? prev : [...prev, shard]))\n\n return () => {\n setShards((prev) => prev.filter((item) => item !== shard))\n }\n }, [])\n\n const onActivation = useCallback(() => {\n if (initialFocusRef?.current) {\n initialFocusRef.current.focus()\n } else if (contentRef?.current) {\n const focusables = getFocusableElements(contentRef.current)\n\n if (focusables.length === 0)\n requestAnimationFrame(() => {\n contentRef.current?.focus()\n })\n }\n }, [initialFocusRef, contentRef])\n\n const onDeactivation = useCallback(() => {\n finalFocusRef?.current?.focus()\n }, [finalFocusRef])\n\n return (\n <FocusLockShardContext value={registerShard}>\n <InternalFocusLock\n autoFocus={autoFocus}\n crossFrame={lockFocusAcrossFrames}\n disabled={disabled}\n persistentFocus={persistentFocus}\n returnFocus={returnFocus}\n shards={shards}\n onActivation={onActivation}\n onDeactivation={onDeactivation}\n >\n {children}\n </InternalFocusLock>\n </FocusLockShardContext>\n )\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,CAAC,uBAAuB,qBAAqBA,gBAAAA,cAEjD;CAAE,MAAM;CAAyB,QAAQ;AAAM,CAAC;AAIlD,MAAM,qBAAA,GAAA,oBAAA,cAAA,eAAA,CAAmCC,iBAAAA,OAAc;;;;;;AAsDvD,MAAa,aAAiC,EAC5C,WACA,UACA,YACA,UACA,eACA,iBACA,uBACA,iBACA,mBACI;CACJ,MAAM,CAAC,QAAQ,cAAA,GAAA,MAAA,SAAA,CAAqC,CAAC,CAAC;CACtD,MAAM,cAAc,gBAAgB,CAAC;CAErC,MAAM,iBAAA,GAAA,MAAA,YAAA,EAA6B,UAAuB;EACxD,WAAW,SAAU,KAAK,SAAS,KAAK,IAAI,OAAO,CAAC,GAAG,MAAM,KAAK,CAAE;EAEpE,aAAa;GACX,WAAW,SAAS,KAAK,QAAQ,SAAS,SAAS,KAAK,CAAC;EAC3D;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAA,GAAA,MAAA,YAAA,OAAiC;EACrC,IAAI,iBAAiB,SACnB,gBAAgB,QAAQ,MAAM;OACzB,IAAI,YAAY,SACmB;QAAA,GAAA,oBAAA,cAAA,qBAAA,CAAA,WAAW,OAEtC,CAAC,CAAC,WAAW,GACxB,4BAA4B;IAC1B,WAAW,SAAS,MAAM;GAC5B,CAAC;EAAA;CAEP,GAAG,CAAC,iBAAiB,UAAU,CAAC;CAEhC,MAAM,kBAAA,GAAA,MAAA,YAAA,OAAmC;EACvC,eAAe,SAAS,MAAM;CAChC,GAAG,CAAC,aAAa,CAAC;CAElB,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,uBAAD;EAAuB,OAAO;EAC5B,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,mBAAD;GACa;GACX,YAAY;GACF;GACO;GACJ;GACL;GACM;GACE;GAEf;EACgB,CAAA;CACE,CAAA;AAE3B"}
|
|
@@ -6,13 +6,13 @@ const require_props = require("../../core/components/props.cjs");
|
|
|
6
6
|
const require_create_component = require("../../core/components/create-component.cjs");
|
|
7
7
|
const require_factory$1 = require("../motion/factory.cjs");
|
|
8
8
|
const require_hooks_use_value_index = require("../../hooks/use-value/index.cjs");
|
|
9
|
+
const require_focus_lock = require("../focus-lock/focus-lock.cjs");
|
|
9
10
|
const require_portal = require("../portal/portal.cjs");
|
|
10
11
|
const require_popover = require("../popover/popover.cjs");
|
|
11
12
|
const require_button = require("../button/button.cjs");
|
|
12
13
|
const require_close_button = require("../close-button/close-button.cjs");
|
|
13
14
|
const require_modal_style = require("./modal.style.cjs");
|
|
14
15
|
const require_fade = require("../fade/fade.cjs");
|
|
15
|
-
const require_focus_lock = require("../focus-lock/focus-lock.cjs");
|
|
16
16
|
const require_use_modal = require("./use-modal.cjs");
|
|
17
17
|
let react = require("react");
|
|
18
18
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const require_ssr = require("../../utils/ssr.cjs");
|
|
3
3
|
const require_utils_index = require("../../utils/index.cjs");
|
|
4
4
|
const require_environment_provider = require("../../core/system/environment-provider.cjs");
|
|
5
|
+
const require_focus_lock = require("../focus-lock/focus-lock.cjs");
|
|
5
6
|
let react = require("react");
|
|
6
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
8
|
let react_dom = require("react-dom");
|
|
@@ -17,14 +18,29 @@ const getPortalNode = (node) => {
|
|
|
17
18
|
* @see https://yamada-ui.com/docs/components/portal
|
|
18
19
|
*/
|
|
19
20
|
const Portal = ({ children, containerRef: ref, disabled }) => {
|
|
21
|
+
const shardRef = (0, react.useRef)(null);
|
|
20
22
|
const [target, setTarget] = (0, react.useState)(ref?.current);
|
|
21
23
|
const ssr = require_ssr.useSsr();
|
|
22
24
|
const { getRootNode } = require_environment_provider.useEnvironment();
|
|
25
|
+
const registerShard = require_focus_lock.useFocusLockShard();
|
|
23
26
|
(0, react.useEffect)(() => {
|
|
24
27
|
setTarget(() => ref?.current);
|
|
25
28
|
}, [ref]);
|
|
29
|
+
(0, react.useEffect)(() => {
|
|
30
|
+
const shard = shardRef.current;
|
|
31
|
+
if (disabled || ssr || !shard) return;
|
|
32
|
+
return registerShard?.(shard);
|
|
33
|
+
}, [
|
|
34
|
+
disabled,
|
|
35
|
+
registerShard,
|
|
36
|
+
ssr
|
|
37
|
+
]);
|
|
26
38
|
if (ssr || disabled) return children;
|
|
27
39
|
const container = target ?? getPortalNode(getRootNode());
|
|
40
|
+
if (registerShard) return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
41
|
+
ref: shardRef,
|
|
42
|
+
children
|
|
43
|
+
}), container);
|
|
28
44
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: react.Children.map(children, (child) => (0, react_dom.createPortal)(child, container)) });
|
|
29
45
|
};
|
|
30
46
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.cjs","names":["useSsr","useEnvironment","Children"],"sources":["../../../../src/components/portal/portal.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport type { RootNode } from \"../../core\"\nimport { Children, useEffect, useState } from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { useEnvironment } from \"../../core\"\nimport { getDocument, isShadowRoot, useSsr } from \"../../utils\"\n\nconst getPortalNode = (node?: RootNode) => {\n const rootNode = node?.getRootNode()\n\n if (isShadowRoot(rootNode)) return rootNode\n\n return getDocument(node).body\n}\n\nexport interface PortalProps extends PropsWithChildren {\n /**\n * The `ref` to the component where the portal will be attached to.\n */\n containerRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the forwarding will be disabled.\n */\n disabled?: boolean\n}\n\n/**\n * `Portal` is a component that renders elements outside of the current `DOM` hierarchy.\n *\n * @see https://yamada-ui.com/docs/components/portal\n */\nexport const Portal: FC<PortalProps> = ({\n children,\n containerRef: ref,\n disabled,\n}) => {\n const [target, setTarget] = useState(ref?.current)\n const ssr = useSsr()\n const { getRootNode } = useEnvironment()\n\n useEffect(() => {\n setTarget(() => ref?.current)\n }, [ref])\n\n if (ssr || disabled) return children\n\n const container = target ?? getPortalNode(getRootNode())\n\n return (\n <>{Children.map(children, (child) => createPortal(child, container))}</>\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"portal.cjs","names":["useSsr","useEnvironment","useFocusLockShard","Children"],"sources":["../../../../src/components/portal/portal.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport type { RootNode } from \"../../core\"\nimport { Children, useEffect, useRef, useState } from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { useEnvironment } from \"../../core\"\nimport { getDocument, isShadowRoot, useSsr } from \"../../utils\"\nimport { useFocusLockShard } from \"../focus-lock\"\n\nconst getPortalNode = (node?: RootNode) => {\n const rootNode = node?.getRootNode()\n\n if (isShadowRoot(rootNode)) return rootNode\n\n return getDocument(node).body\n}\n\nexport interface PortalProps extends PropsWithChildren {\n /**\n * The `ref` to the component where the portal will be attached to.\n */\n containerRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the forwarding will be disabled.\n */\n disabled?: boolean\n}\n\n/**\n * `Portal` is a component that renders elements outside of the current `DOM` hierarchy.\n *\n * @see https://yamada-ui.com/docs/components/portal\n */\nexport const Portal: FC<PortalProps> = ({\n children,\n containerRef: ref,\n disabled,\n}) => {\n const shardRef = useRef<HTMLDivElement>(null)\n const [target, setTarget] = useState(ref?.current)\n const ssr = useSsr()\n const { getRootNode } = useEnvironment()\n const registerShard = useFocusLockShard()\n\n useEffect(() => {\n setTarget(() => ref?.current)\n }, [ref])\n\n useEffect(() => {\n const shard = shardRef.current\n\n if (disabled || ssr || !shard) return\n\n return registerShard?.(shard)\n }, [disabled, registerShard, ssr])\n\n if (ssr || disabled) return children\n\n const container = target ?? getPortalNode(getRootNode())\n\n if (registerShard)\n return createPortal(<div ref={shardRef}>{children}</div>, container)\n\n return (\n <>{Children.map(children, (child) => createPortal(child, container))}</>\n )\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,iBAAiB,SAAoB;CACzC,MAAM,WAAW,MAAM,YAAY;CAEnC,KAAA,GAAA,oBAAA,cAAA,aAAA,CAAiB,QAAQ,GAAG,OAAO;CAEnC,QAAA,GAAA,oBAAA,cAAA,YAAA,CAAmB,IAAI,CAAC,CAAC;AAC3B;;;;;;AAkBA,MAAa,UAA2B,EACtC,UACA,cAAc,KACd,eACI;CACJ,MAAM,YAAA,GAAA,MAAA,OAAA,CAAkC,IAAI;CAC5C,MAAM,CAAC,QAAQ,cAAA,GAAA,MAAA,SAAA,CAAsB,KAAK,OAAO;CACjD,MAAM,MAAMA,YAAAA,OAAO;CACnB,MAAM,EAAE,gBAAgBC,6BAAAA,eAAe;CACvC,MAAM,gBAAgBC,mBAAAA,kBAAkB;CAExC,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,gBAAgB,KAAK,OAAO;CAC9B,GAAG,CAAC,GAAG,CAAC;CAER,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,QAAQ,SAAS;EAEvB,IAAI,YAAY,OAAO,CAAC,OAAO;EAE/B,OAAO,gBAAgB,KAAK;CAC9B,GAAG;EAAC;EAAU;EAAe;CAAG,CAAC;CAEjC,IAAI,OAAO,UAAU,OAAO;CAE5B,MAAM,YAAY,UAAU,cAAc,YAAY,CAAC;CAEvD,IAAI,eACF,QAAA,GAAA,UAAA,aAAA,CAAoB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,KAAK;EAAW;CAAc,CAAA,GAAG,SAAS;CAErE,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAA,kBAAA,UAAA,EAAA,UAAGC,MAAAA,SAAS,IAAI,WAAW,WAAA,GAAA,UAAA,aAAA,CAAuB,OAAO,SAAS,CAAC,EAAI,CAAA;AAE3E"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1826,6 +1826,7 @@ const require_namespace$2 = require("./components/native-popover/namespace.cjs")
|
|
|
1826
1826
|
const require_popover_style = require("./components/popover/popover.style.cjs");
|
|
1827
1827
|
const require_fade_scale_style = require("./components/fade-scale/fade-scale.style.cjs");
|
|
1828
1828
|
const require_fade_scale = require("./components/fade-scale/fade-scale.cjs");
|
|
1829
|
+
const require_focus_lock = require("./components/focus-lock/focus-lock.cjs");
|
|
1829
1830
|
const require_portal = require("./components/portal/portal.cjs");
|
|
1830
1831
|
const require_slide_fade_style = require("./components/slide-fade/slide-fade.style.cjs");
|
|
1831
1832
|
const require_slide_fade = require("./components/slide-fade/slide-fade.cjs");
|
|
@@ -2043,7 +2044,6 @@ const require_namespace$31 = require("./components/data-list/namespace.cjs");
|
|
|
2043
2044
|
const require_modal_style = require("./components/modal/modal.style.cjs");
|
|
2044
2045
|
const require_fade_style = require("./components/fade/fade.style.cjs");
|
|
2045
2046
|
const require_fade = require("./components/fade/fade.cjs");
|
|
2046
|
-
const require_focus_lock = require("./components/focus-lock/focus-lock.cjs");
|
|
2047
2047
|
const require_use_modal = require("./components/modal/use-modal.cjs");
|
|
2048
2048
|
const require_modal = require("./components/modal/modal.cjs");
|
|
2049
2049
|
const require_namespace$32 = require("./components/modal/namespace.cjs");
|
|
@@ -5086,6 +5086,7 @@ var src_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
5086
5086
|
useFlexPropsContext: () => require_flex.useFlexPropsContext,
|
|
5087
5087
|
useFlipPropsContext: () => require_flip.useFlipPropsContext,
|
|
5088
5088
|
useFloatPropsContext: () => require_float.useFloatPropsContext,
|
|
5089
|
+
useFocusLockShard: () => require_focus_lock.useFocusLockShard,
|
|
5089
5090
|
useFocusOnPointerDown: () => require_hooks_use_focus_index.useFocusOnPointerDown,
|
|
5090
5091
|
useFocusOnShow: () => require_hooks_use_focus_index.useFocusOnShow,
|
|
5091
5092
|
useFormContext: () => require_form.useFormContext,
|
|
@@ -8502,6 +8503,7 @@ exports.useFindChildren = require_children.useFindChildren;
|
|
|
8502
8503
|
exports.useFlexPropsContext = require_flex.useFlexPropsContext;
|
|
8503
8504
|
exports.useFlipPropsContext = require_flip.useFlipPropsContext;
|
|
8504
8505
|
exports.useFloatPropsContext = require_float.useFloatPropsContext;
|
|
8506
|
+
exports.useFocusLockShard = require_focus_lock.useFocusLockShard;
|
|
8505
8507
|
exports.useFocusOnPointerDown = require_hooks_use_focus_index.useFocusOnPointerDown;
|
|
8506
8508
|
exports.useFocusOnShow = require_hooks_use_focus_index.useFocusOnShow;
|
|
8507
8509
|
exports.useFormContext = require_form.useFormContext;
|
|
@@ -5,11 +5,11 @@ import { styled } from "../../core/system/factory.js";
|
|
|
5
5
|
import { createSlotComponent } from "../../core/components/create-component.js";
|
|
6
6
|
import { motion as motion$1 } from "../motion/factory.js";
|
|
7
7
|
import { useValue } from "../../hooks/use-value/index.js";
|
|
8
|
+
import { FocusLock } from "../focus-lock/focus-lock.js";
|
|
8
9
|
import { Portal } from "../portal/portal.js";
|
|
9
10
|
import { Button } from "../button/button.js";
|
|
10
11
|
import { CloseButton } from "../close-button/close-button.js";
|
|
11
12
|
import { fadeVariants } from "../fade/fade.js";
|
|
12
|
-
import { FocusLock } from "../focus-lock/focus-lock.js";
|
|
13
13
|
import { drawerStyle } from "./drawer.style.js";
|
|
14
14
|
import { Slide } from "../slide/slide.js";
|
|
15
15
|
import { useDrawer } from "./use-drawer.js";
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { createContext as createContext$1 } from "../../utils/context.js";
|
|
2
3
|
import { utils_exports } from "../../utils/index.js";
|
|
3
|
-
import { useCallback } from "react";
|
|
4
|
+
import { useCallback, useState } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import ReactFocusLock from "react-focus-lock";
|
|
6
7
|
//#region src/components/focus-lock/focus-lock.tsx
|
|
8
|
+
const [FocusLockShardContext, useFocusLockShard] = createContext$1({
|
|
9
|
+
name: "FocusLockShardContext",
|
|
10
|
+
strict: false
|
|
11
|
+
});
|
|
7
12
|
const InternalFocusLock = (0, utils_exports.interopDefault)(ReactFocusLock);
|
|
8
13
|
/**
|
|
9
14
|
* `FocusLock` is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range.
|
|
@@ -11,7 +16,14 @@ const InternalFocusLock = (0, utils_exports.interopDefault)(ReactFocusLock);
|
|
|
11
16
|
* @see https://yamada-ui.com/docs/components/focus-lock
|
|
12
17
|
*/
|
|
13
18
|
const FocusLock = ({ autoFocus, children, contentRef, disabled, finalFocusRef, initialFocusRef, lockFocusAcrossFrames, persistentFocus, restoreFocus }) => {
|
|
19
|
+
const [shards, setShards] = useState([]);
|
|
14
20
|
const returnFocus = restoreFocus && !finalFocusRef;
|
|
21
|
+
const registerShard = useCallback((shard) => {
|
|
22
|
+
setShards((prev) => prev.includes(shard) ? prev : [...prev, shard]);
|
|
23
|
+
return () => {
|
|
24
|
+
setShards((prev) => prev.filter((item) => item !== shard));
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
15
27
|
const onActivation = useCallback(() => {
|
|
16
28
|
if (initialFocusRef?.current) initialFocusRef.current.focus();
|
|
17
29
|
else if (contentRef?.current) {
|
|
@@ -23,18 +35,22 @@ const FocusLock = ({ autoFocus, children, contentRef, disabled, finalFocusRef, i
|
|
|
23
35
|
const onDeactivation = useCallback(() => {
|
|
24
36
|
finalFocusRef?.current?.focus();
|
|
25
37
|
}, [finalFocusRef]);
|
|
26
|
-
return /* @__PURE__ */ jsx(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
return /* @__PURE__ */ jsx(FocusLockShardContext, {
|
|
39
|
+
value: registerShard,
|
|
40
|
+
children: /* @__PURE__ */ jsx(InternalFocusLock, {
|
|
41
|
+
autoFocus,
|
|
42
|
+
crossFrame: lockFocusAcrossFrames,
|
|
43
|
+
disabled,
|
|
44
|
+
persistentFocus,
|
|
45
|
+
returnFocus,
|
|
46
|
+
shards,
|
|
47
|
+
onActivation,
|
|
48
|
+
onDeactivation,
|
|
49
|
+
children
|
|
50
|
+
})
|
|
35
51
|
});
|
|
36
52
|
};
|
|
37
53
|
//#endregion
|
|
38
|
-
export { FocusLock };
|
|
54
|
+
export { FocusLock, useFocusLockShard };
|
|
39
55
|
|
|
40
56
|
//# sourceMappingURL=focus-lock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-lock.js","names":[],"sources":["../../../../src/components/focus-lock/focus-lock.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport { useCallback } from \"react\"\nimport ReactFocusLock from \"react-focus-lock\"\nimport {
|
|
1
|
+
{"version":3,"file":"focus-lock.js","names":["createContext"],"sources":["../../../../src/components/focus-lock/focus-lock.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport { useCallback, useState } from \"react\"\nimport ReactFocusLock from \"react-focus-lock\"\nimport {\n createContext,\n getFocusableElements,\n interopDefault,\n} from \"../../utils\"\n\nconst [FocusLockShardContext, useFocusLockShard] = createContext<\n ((shard: HTMLElement) => () => void) | undefined\n>({ name: \"FocusLockShardContext\", strict: false })\n\nexport { useFocusLockShard }\n\nconst InternalFocusLock = interopDefault(ReactFocusLock)\n\nexport interface FocusLockProps extends PropsWithChildren {\n /**\n * If `true`, the first focusable element within the `children` will auto-focused once `FocusLock` mounts.\n *\n * @default false\n */\n autoFocus?: boolean\n /**\n * The `ref` of the wrapper for which the focus-lock wraps.\n */\n contentRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, focus trapping will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * `ref` of the element to return focus to when `FocusLock` unmounts.\n */\n finalFocusRef?: RefObject<HTMLElement | null>\n /**\n * `ref` of the element to receive focus initially.\n */\n initialFocusRef?: RefObject<HTMLElement | null>\n /**\n * Enables aggressive focus capturing within iframes.\n * - If `true`: keep focus in the lock, no matter where lock is active.\n * - If `false`: allows focus to move outside of iframe.\n *\n * @default false\n */\n lockFocusAcrossFrames?: boolean\n /**\n * If `true`, disables text selections inside, and outside focus lock.\n *\n * @default false\n */\n persistentFocus?: boolean\n /**\n * If `true`, focus will be restored to the element that triggered the `FocusLock` once it unmounts.\n *\n * @default false\n */\n restoreFocus?: boolean\n}\n\n/**\n * `FocusLock` is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range.\n *\n * @see https://yamada-ui.com/docs/components/focus-lock\n */\nexport const FocusLock: FC<FocusLockProps> = ({\n autoFocus,\n children,\n contentRef,\n disabled,\n finalFocusRef,\n initialFocusRef,\n lockFocusAcrossFrames,\n persistentFocus,\n restoreFocus,\n}) => {\n const [shards, setShards] = useState<HTMLElement[]>([])\n const returnFocus = restoreFocus && !finalFocusRef\n\n const registerShard = useCallback((shard: HTMLElement) => {\n setShards((prev) => (prev.includes(shard) ? prev : [...prev, shard]))\n\n return () => {\n setShards((prev) => prev.filter((item) => item !== shard))\n }\n }, [])\n\n const onActivation = useCallback(() => {\n if (initialFocusRef?.current) {\n initialFocusRef.current.focus()\n } else if (contentRef?.current) {\n const focusables = getFocusableElements(contentRef.current)\n\n if (focusables.length === 0)\n requestAnimationFrame(() => {\n contentRef.current?.focus()\n })\n }\n }, [initialFocusRef, contentRef])\n\n const onDeactivation = useCallback(() => {\n finalFocusRef?.current?.focus()\n }, [finalFocusRef])\n\n return (\n <FocusLockShardContext value={registerShard}>\n <InternalFocusLock\n autoFocus={autoFocus}\n crossFrame={lockFocusAcrossFrames}\n disabled={disabled}\n persistentFocus={persistentFocus}\n returnFocus={returnFocus}\n shards={shards}\n onActivation={onActivation}\n onDeactivation={onDeactivation}\n >\n {children}\n </InternalFocusLock>\n </FocusLockShardContext>\n )\n}\n"],"mappings":";;;;;;;AAWA,MAAM,CAAC,uBAAuB,qBAAqBA,gBAEjD;CAAE,MAAM;CAAyB,QAAQ;AAAM,CAAC;AAIlD,MAAM,qBAAA,GAAA,cAAA,eAAA,CAAmC,cAAc;;;;;;AAsDvD,MAAa,aAAiC,EAC5C,WACA,UACA,YACA,UACA,eACA,iBACA,uBACA,iBACA,mBACI;CACJ,MAAM,CAAC,QAAQ,aAAa,SAAwB,CAAC,CAAC;CACtD,MAAM,cAAc,gBAAgB,CAAC;CAErC,MAAM,gBAAgB,aAAa,UAAuB;EACxD,WAAW,SAAU,KAAK,SAAS,KAAK,IAAI,OAAO,CAAC,GAAG,MAAM,KAAK,CAAE;EAEpE,aAAa;GACX,WAAW,SAAS,KAAK,QAAQ,SAAS,SAAS,KAAK,CAAC;EAC3D;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,eAAe,kBAAkB;EACrC,IAAI,iBAAiB,SACnB,gBAAgB,QAAQ,MAAM;OACzB,IAAI,YAAY,SACmB;QAAA,GAAA,cAAA,qBAAA,CAAA,WAAW,OAEtC,CAAC,CAAC,WAAW,GACxB,4BAA4B;IAC1B,WAAW,SAAS,MAAM;GAC5B,CAAC;EAAA;CAEP,GAAG,CAAC,iBAAiB,UAAU,CAAC;CAEhC,MAAM,iBAAiB,kBAAkB;EACvC,eAAe,SAAS,MAAM;CAChC,GAAG,CAAC,aAAa,CAAC;CAElB,OACE,oBAAC,uBAAD;EAAuB,OAAO;EAC5B,UAAA,oBAAC,mBAAD;GACa;GACX,YAAY;GACF;GACO;GACJ;GACL;GACM;GACE;GAEf;EACgB,CAAA;CACE,CAAA;AAE3B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FocusLock } from "./focus-lock.js";
|
|
2
|
-
export { FocusLock };
|
|
1
|
+
import { FocusLock, useFocusLockShard } from "./focus-lock.js";
|
|
2
|
+
export { FocusLock, useFocusLockShard };
|
|
@@ -6,13 +6,13 @@ import { mergeProps } from "../../core/components/props.js";
|
|
|
6
6
|
import { createSlotComponent } from "../../core/components/create-component.js";
|
|
7
7
|
import { motion as motion$1 } from "../motion/factory.js";
|
|
8
8
|
import { useValue } from "../../hooks/use-value/index.js";
|
|
9
|
+
import { FocusLock } from "../focus-lock/focus-lock.js";
|
|
9
10
|
import { Portal } from "../portal/portal.js";
|
|
10
11
|
import { usePopupAnimationProps } from "../popover/popover.js";
|
|
11
12
|
import { Button } from "../button/button.js";
|
|
12
13
|
import { CloseButton } from "../close-button/close-button.js";
|
|
13
14
|
import { modalStyle } from "./modal.style.js";
|
|
14
15
|
import { fadeVariants } from "../fade/fade.js";
|
|
15
|
-
import { FocusLock } from "../focus-lock/focus-lock.js";
|
|
16
16
|
import { useModal } from "./use-modal.js";
|
|
17
17
|
import { useMemo } from "react";
|
|
18
18
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { useSsr } from "../../utils/ssr.js";
|
|
3
3
|
import { utils_exports } from "../../utils/index.js";
|
|
4
4
|
import { useEnvironment } from "../../core/system/environment-provider.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useFocusLockShard } from "../focus-lock/focus-lock.js";
|
|
6
|
+
import { Children, useEffect, useRef, useState } from "react";
|
|
6
7
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
7
8
|
import { createPortal } from "react-dom";
|
|
8
9
|
//#region src/components/portal/portal.tsx
|
|
@@ -17,14 +18,29 @@ const getPortalNode = (node) => {
|
|
|
17
18
|
* @see https://yamada-ui.com/docs/components/portal
|
|
18
19
|
*/
|
|
19
20
|
const Portal = ({ children, containerRef: ref, disabled }) => {
|
|
21
|
+
const shardRef = useRef(null);
|
|
20
22
|
const [target, setTarget] = useState(ref?.current);
|
|
21
23
|
const ssr = useSsr();
|
|
22
24
|
const { getRootNode } = useEnvironment();
|
|
25
|
+
const registerShard = useFocusLockShard();
|
|
23
26
|
useEffect(() => {
|
|
24
27
|
setTarget(() => ref?.current);
|
|
25
28
|
}, [ref]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const shard = shardRef.current;
|
|
31
|
+
if (disabled || ssr || !shard) return;
|
|
32
|
+
return registerShard?.(shard);
|
|
33
|
+
}, [
|
|
34
|
+
disabled,
|
|
35
|
+
registerShard,
|
|
36
|
+
ssr
|
|
37
|
+
]);
|
|
26
38
|
if (ssr || disabled) return children;
|
|
27
39
|
const container = target ?? getPortalNode(getRootNode());
|
|
40
|
+
if (registerShard) return createPortal(/* @__PURE__ */ jsx("div", {
|
|
41
|
+
ref: shardRef,
|
|
42
|
+
children
|
|
43
|
+
}), container);
|
|
28
44
|
return /* @__PURE__ */ jsx(Fragment$1, { children: Children.map(children, (child) => createPortal(child, container)) });
|
|
29
45
|
};
|
|
30
46
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.js","names":[],"sources":["../../../../src/components/portal/portal.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport type { RootNode } from \"../../core\"\nimport { Children, useEffect, useState } from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { useEnvironment } from \"../../core\"\nimport { getDocument, isShadowRoot, useSsr } from \"../../utils\"\n\nconst getPortalNode = (node?: RootNode) => {\n const rootNode = node?.getRootNode()\n\n if (isShadowRoot(rootNode)) return rootNode\n\n return getDocument(node).body\n}\n\nexport interface PortalProps extends PropsWithChildren {\n /**\n * The `ref` to the component where the portal will be attached to.\n */\n containerRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the forwarding will be disabled.\n */\n disabled?: boolean\n}\n\n/**\n * `Portal` is a component that renders elements outside of the current `DOM` hierarchy.\n *\n * @see https://yamada-ui.com/docs/components/portal\n */\nexport const Portal: FC<PortalProps> = ({\n children,\n containerRef: ref,\n disabled,\n}) => {\n const [target, setTarget] = useState(ref?.current)\n const ssr = useSsr()\n const { getRootNode } = useEnvironment()\n\n useEffect(() => {\n setTarget(() => ref?.current)\n }, [ref])\n\n if (ssr || disabled) return children\n\n const container = target ?? getPortalNode(getRootNode())\n\n return (\n <>{Children.map(children, (child) => createPortal(child, container))}</>\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"portal.js","names":[],"sources":["../../../../src/components/portal/portal.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, RefObject } from \"react\"\nimport type { RootNode } from \"../../core\"\nimport { Children, useEffect, useRef, useState } from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { useEnvironment } from \"../../core\"\nimport { getDocument, isShadowRoot, useSsr } from \"../../utils\"\nimport { useFocusLockShard } from \"../focus-lock\"\n\nconst getPortalNode = (node?: RootNode) => {\n const rootNode = node?.getRootNode()\n\n if (isShadowRoot(rootNode)) return rootNode\n\n return getDocument(node).body\n}\n\nexport interface PortalProps extends PropsWithChildren {\n /**\n * The `ref` to the component where the portal will be attached to.\n */\n containerRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the forwarding will be disabled.\n */\n disabled?: boolean\n}\n\n/**\n * `Portal` is a component that renders elements outside of the current `DOM` hierarchy.\n *\n * @see https://yamada-ui.com/docs/components/portal\n */\nexport const Portal: FC<PortalProps> = ({\n children,\n containerRef: ref,\n disabled,\n}) => {\n const shardRef = useRef<HTMLDivElement>(null)\n const [target, setTarget] = useState(ref?.current)\n const ssr = useSsr()\n const { getRootNode } = useEnvironment()\n const registerShard = useFocusLockShard()\n\n useEffect(() => {\n setTarget(() => ref?.current)\n }, [ref])\n\n useEffect(() => {\n const shard = shardRef.current\n\n if (disabled || ssr || !shard) return\n\n return registerShard?.(shard)\n }, [disabled, registerShard, ssr])\n\n if (ssr || disabled) return children\n\n const container = target ?? getPortalNode(getRootNode())\n\n if (registerShard)\n return createPortal(<div ref={shardRef}>{children}</div>, container)\n\n return (\n <>{Children.map(children, (child) => createPortal(child, container))}</>\n )\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,iBAAiB,SAAoB;CACzC,MAAM,WAAW,MAAM,YAAY;CAEnC,KAAA,GAAA,cAAA,aAAA,CAAiB,QAAQ,GAAG,OAAO;CAEnC,QAAA,GAAA,cAAA,YAAA,CAAmB,IAAI,CAAC,CAAC;AAC3B;;;;;;AAkBA,MAAa,UAA2B,EACtC,UACA,cAAc,KACd,eACI;CACJ,MAAM,WAAW,OAAuB,IAAI;CAC5C,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK,OAAO;CACjD,MAAM,MAAM,OAAO;CACnB,MAAM,EAAE,gBAAgB,eAAe;CACvC,MAAM,gBAAgB,kBAAkB;CAExC,gBAAgB;EACd,gBAAgB,KAAK,OAAO;CAC9B,GAAG,CAAC,GAAG,CAAC;CAER,gBAAgB;EACd,MAAM,QAAQ,SAAS;EAEvB,IAAI,YAAY,OAAO,CAAC,OAAO;EAE/B,OAAO,gBAAgB,KAAK;CAC9B,GAAG;EAAC;EAAU;EAAe;CAAG,CAAC;CAEjC,IAAI,OAAO,UAAU,OAAO;CAE5B,MAAM,YAAY,UAAU,cAAc,YAAY,CAAC;CAEvD,IAAI,eACF,OAAO,aAAa,oBAAC,OAAD;EAAK,KAAK;EAAW;CAAc,CAAA,GAAG,SAAS;CAErE,OACE,oBAAA,YAAA,EAAA,UAAG,SAAS,IAAI,WAAW,UAAU,aAAa,OAAO,SAAS,CAAC,EAAI,CAAA;AAE3E"}
|