@react-aria/disclosure 3.0.8 → 3.1.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.
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useDisclosure.main.js +41 -8
- package/dist/useDisclosure.main.js.map +1 -1
- package/dist/useDisclosure.mjs +41 -8
- package/dist/useDisclosure.module.js +41 -8
- package/dist/useDisclosure.module.js.map +1 -1
- package/package.json +5 -5
- package/src/.DS_Store +0 -0
- package/src/useDisclosure.ts +52 -11
package/dist/types.d.ts
CHANGED
|
@@ -23,6 +23,6 @@ export interface DisclosureAria {
|
|
|
23
23
|
* @param state - State for the disclosure, as returned by `useDisclosureState`.
|
|
24
24
|
* @param ref - A ref for the disclosure panel.
|
|
25
25
|
*/
|
|
26
|
-
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<
|
|
26
|
+
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria;
|
|
27
27
|
|
|
28
28
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAmBA;IACE,0CAA0C;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oEAAoE;IACpE,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;IACE,uCAAuC;IACvC,WAAW,EAAE,eAAe,CAAC;IAC7B,sCAAsC;IACtC,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAED;;;;;GAKG;AACH,8BAA8B,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,
|
|
1
|
+
{"mappings":";;;AAmBA;IACE,0CAA0C;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oEAAoE;IACpE,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;IACE,uCAAuC;IACvC,WAAW,EAAE,eAAe,CAAC;IAC7B,sCAAsC;IACtC,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAED;;;;;GAKG;AACH,8BAA8B,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,cAAc,CAqHpI","sources":["packages/@react-aria/disclosure/src/packages/@react-aria/disclosure/src/useDisclosure.ts","packages/@react-aria/disclosure/src/packages/@react-aria/disclosure/src/index.ts","packages/@react-aria/disclosure/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDisclosure} from './useDisclosure';\nexport type {DisclosureAria, AriaDisclosureProps} from './useDisclosure';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -28,7 +28,6 @@ function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
|
|
|
28
28
|
let triggerId = (0, $l3cx6$reactariautils.useId)();
|
|
29
29
|
let panelId = (0, $l3cx6$reactariautils.useId)();
|
|
30
30
|
let isSSR = (0, $l3cx6$reactariassr.useIsSSR)();
|
|
31
|
-
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
32
31
|
let raf = (0, $l3cx6$react.useRef)(null);
|
|
33
32
|
let handleBeforeMatch = (0, $l3cx6$react.useCallback)(()=>{
|
|
34
33
|
// Wait a frame to revert browser's removal of hidden attribute
|
|
@@ -44,20 +43,54 @@ function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
|
|
|
44
43
|
state
|
|
45
44
|
]);
|
|
46
45
|
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
47
|
-
(0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch',
|
|
46
|
+
(0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', handleBeforeMatch);
|
|
47
|
+
let isExpandedRef = (0, $l3cx6$react.useRef)(null);
|
|
48
48
|
(0, $l3cx6$reactariautils.useLayoutEffect)(()=>{
|
|
49
49
|
// Cancel any pending RAF to prevent stale updates
|
|
50
50
|
if (raf.current) cancelAnimationFrame(raf.current);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
51
|
+
if (ref.current && !isDisabled && !isSSR) {
|
|
52
|
+
let panel = ref.current;
|
|
53
|
+
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
54
|
+
// On initial render (and in tests), set attributes without animation.
|
|
55
|
+
if (state.isExpanded) {
|
|
56
|
+
panel.removeAttribute('hidden');
|
|
57
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
58
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
59
|
+
} else {
|
|
60
|
+
panel.setAttribute('hidden', 'until-found');
|
|
61
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
62
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
63
|
+
}
|
|
64
|
+
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
65
|
+
if (state.isExpanded) {
|
|
66
|
+
panel.removeAttribute('hidden');
|
|
67
|
+
// Set the width and height as pixels so they can be animated.
|
|
68
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
69
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
70
|
+
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>{
|
|
71
|
+
// After the animations complete, switch back to auto so the content can resize.
|
|
72
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
73
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
74
|
+
}).catch(()=>{});
|
|
75
|
+
} else {
|
|
76
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
77
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
78
|
+
// Force style re-calculation to trigger animations.
|
|
79
|
+
window.getComputedStyle(panel).height;
|
|
80
|
+
// Animate to zero size.
|
|
81
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
82
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
83
|
+
// Wait for animations to apply the hidden attribute.
|
|
84
|
+
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>panel.setAttribute('hidden', 'until-found')).catch(()=>{});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
isExpandedRef.current = state.isExpanded;
|
|
55
88
|
}
|
|
56
89
|
}, [
|
|
57
90
|
isDisabled,
|
|
58
91
|
ref,
|
|
59
92
|
state.isExpanded,
|
|
60
|
-
|
|
93
|
+
isSSR
|
|
61
94
|
]);
|
|
62
95
|
(0, $l3cx6$react.useEffect)(()=>{
|
|
63
96
|
return ()=>{
|
|
@@ -83,7 +116,7 @@ function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
|
|
|
83
116
|
role: 'group',
|
|
84
117
|
'aria-labelledby': triggerId,
|
|
85
118
|
'aria-hidden': !state.isExpanded,
|
|
86
|
-
hidden:
|
|
119
|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QAAC;QAAY;QAAK,MAAM,UAAU;QAAE;KAAM;IAE7C,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAEpC;IACF,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YACX,IAAI;YACJ,iBAAiB,MAAM,UAAU;YACjC,iBAAiB;YACjB,SAAS,CAAC;gBACR,IAAI,CAAC,cAAc,EAAE,WAAW,KAAK,YACnC,MAAM,MAAM;YAEhB;wBACA;YACA,cAAa,CAAC;gBACZ,IAAI,EAAE,WAAW,KAAK,cAAc,CAAC,YACnC,MAAM,MAAM;YAEhB;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,eAAe,CAAC,MAAM,UAAU;YAChC,QAAQ,AAAC,SAAS,aAAe,cAAc,CAAC,MAAM,UAAU,GAAI;QACtE;IACF;AACF","sources":["packages/@react-aria/disclosure/src/useDisclosure.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the 'License');\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DisclosureState} from '@react-stately/disclosure';\nimport {flushSync} from 'react-dom';\nimport {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';\nimport {useEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport interface AriaDisclosureProps {\n /** Whether the disclosure is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the disclosure's expanded state changes. */\n onExpandedChange?: (isExpanded: boolean) => void,\n /** Whether the disclosure is expanded (controlled). */\n isExpanded?: boolean,\n /** Whether the disclosure is expanded by default (uncontrolled). */\n defaultExpanded?: boolean\n}\n\nexport interface DisclosureAria {\n /** Props for the disclosure button. */\n buttonProps: AriaButtonProps,\n /** Props for the disclosure panel. */\n panelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a disclosure component.\n * @param props - Props for the disclosure.\n * @param state - State for the disclosure, as returned by `useDisclosureState`.\n * @param ref - A ref for the disclosure panel.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let panelId = useId();\n let isSSR = useIsSSR();\n\n let raf = useRef<number | null>(null);\n\n let handleBeforeMatch = useCallback(() => {\n // Wait a frame to revert browser's removal of hidden attribute\n raf.current = requestAnimationFrame(() => {\n if (ref.current) {\n ref.current.setAttribute('hidden', 'until-found');\n }\n });\n // Force sync state update\n flushSync(() => {\n state.toggle();\n });\n }, [ref, state]);\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', handleBeforeMatch);\n\n let isExpandedRef = useRef<boolean | null>(null);\n useLayoutEffect(() => {\n // Cancel any pending RAF to prevent stale updates\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n if (ref.current && !isDisabled && !isSSR) {\n let panel = ref.current;\n\n if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {\n // On initial render (and in tests), set attributes without animation.\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n } else {\n panel.setAttribute('hidden', 'until-found');\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n }\n } else if (state.isExpanded !== isExpandedRef.current) {\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n\n // Set the width and height as pixels so they can be animated.\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => {\n // After the animations complete, switch back to auto so the content can resize.\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n })\n .catch(() => {});\n } else {\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n // Force style re-calculation to trigger animations.\n window.getComputedStyle(panel).height;\n\n // Animate to zero size.\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n\n // Wait for animations to apply the hidden attribute.\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => panel.setAttribute('hidden', 'until-found'))\n .catch(() => {});\n }\n }\n\n isExpandedRef.current = state.isExpanded;\n }\n }, [isDisabled, ref, state.isExpanded, isSSR]);\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': panelId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onPressStart(e) {\n if (e.pointerType === 'keyboard' && !isDisabled) {\n state.toggle();\n }\n }\n },\n panelProps: {\n id: panelId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n 'aria-hidden': !state.isExpanded,\n hidden: (isSSR || isDisabled) ? (isDisabled || !state.isExpanded) : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.main.js.map"}
|
package/dist/useDisclosure.mjs
CHANGED
|
@@ -22,7 +22,6 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
|
22
22
|
let triggerId = (0, $6wN6e$useId)();
|
|
23
23
|
let panelId = (0, $6wN6e$useId)();
|
|
24
24
|
let isSSR = (0, $6wN6e$useIsSSR)();
|
|
25
|
-
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
26
25
|
let raf = (0, $6wN6e$useRef)(null);
|
|
27
26
|
let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
|
|
28
27
|
// Wait a frame to revert browser's removal of hidden attribute
|
|
@@ -38,20 +37,54 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
|
38
37
|
state
|
|
39
38
|
]);
|
|
40
39
|
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
41
|
-
(0, $6wN6e$useEvent)(ref, 'beforematch',
|
|
40
|
+
(0, $6wN6e$useEvent)(ref, 'beforematch', handleBeforeMatch);
|
|
41
|
+
let isExpandedRef = (0, $6wN6e$useRef)(null);
|
|
42
42
|
(0, $6wN6e$useLayoutEffect)(()=>{
|
|
43
43
|
// Cancel any pending RAF to prevent stale updates
|
|
44
44
|
if (raf.current) cancelAnimationFrame(raf.current);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
45
|
+
if (ref.current && !isDisabled && !isSSR) {
|
|
46
|
+
let panel = ref.current;
|
|
47
|
+
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
48
|
+
// On initial render (and in tests), set attributes without animation.
|
|
49
|
+
if (state.isExpanded) {
|
|
50
|
+
panel.removeAttribute('hidden');
|
|
51
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
52
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
53
|
+
} else {
|
|
54
|
+
panel.setAttribute('hidden', 'until-found');
|
|
55
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
56
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
57
|
+
}
|
|
58
|
+
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
59
|
+
if (state.isExpanded) {
|
|
60
|
+
panel.removeAttribute('hidden');
|
|
61
|
+
// Set the width and height as pixels so they can be animated.
|
|
62
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
63
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
64
|
+
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>{
|
|
65
|
+
// After the animations complete, switch back to auto so the content can resize.
|
|
66
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
67
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
68
|
+
}).catch(()=>{});
|
|
69
|
+
} else {
|
|
70
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
71
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
72
|
+
// Force style re-calculation to trigger animations.
|
|
73
|
+
window.getComputedStyle(panel).height;
|
|
74
|
+
// Animate to zero size.
|
|
75
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
76
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
77
|
+
// Wait for animations to apply the hidden attribute.
|
|
78
|
+
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>panel.setAttribute('hidden', 'until-found')).catch(()=>{});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
isExpandedRef.current = state.isExpanded;
|
|
49
82
|
}
|
|
50
83
|
}, [
|
|
51
84
|
isDisabled,
|
|
52
85
|
ref,
|
|
53
86
|
state.isExpanded,
|
|
54
|
-
|
|
87
|
+
isSSR
|
|
55
88
|
]);
|
|
56
89
|
(0, $6wN6e$useEffect)(()=>{
|
|
57
90
|
return ()=>{
|
|
@@ -77,7 +110,7 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
|
77
110
|
role: 'group',
|
|
78
111
|
'aria-labelledby': triggerId,
|
|
79
112
|
'aria-hidden': !state.isExpanded,
|
|
80
|
-
hidden:
|
|
113
|
+
hidden: isSSR || isDisabled ? isDisabled || !state.isExpanded : undefined
|
|
81
114
|
}
|
|
82
115
|
};
|
|
83
116
|
}
|
|
@@ -22,7 +22,6 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
|
22
22
|
let triggerId = (0, $6wN6e$useId)();
|
|
23
23
|
let panelId = (0, $6wN6e$useId)();
|
|
24
24
|
let isSSR = (0, $6wN6e$useIsSSR)();
|
|
25
|
-
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
26
25
|
let raf = (0, $6wN6e$useRef)(null);
|
|
27
26
|
let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
|
|
28
27
|
// Wait a frame to revert browser's removal of hidden attribute
|
|
@@ -38,20 +37,54 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
|
38
37
|
state
|
|
39
38
|
]);
|
|
40
39
|
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
41
|
-
(0, $6wN6e$useEvent)(ref, 'beforematch',
|
|
40
|
+
(0, $6wN6e$useEvent)(ref, 'beforematch', handleBeforeMatch);
|
|
41
|
+
let isExpandedRef = (0, $6wN6e$useRef)(null);
|
|
42
42
|
(0, $6wN6e$useLayoutEffect)(()=>{
|
|
43
43
|
// Cancel any pending RAF to prevent stale updates
|
|
44
44
|
if (raf.current) cancelAnimationFrame(raf.current);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
45
|
+
if (ref.current && !isDisabled && !isSSR) {
|
|
46
|
+
let panel = ref.current;
|
|
47
|
+
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
48
|
+
// On initial render (and in tests), set attributes without animation.
|
|
49
|
+
if (state.isExpanded) {
|
|
50
|
+
panel.removeAttribute('hidden');
|
|
51
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
52
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
53
|
+
} else {
|
|
54
|
+
panel.setAttribute('hidden', 'until-found');
|
|
55
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
56
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
57
|
+
}
|
|
58
|
+
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
59
|
+
if (state.isExpanded) {
|
|
60
|
+
panel.removeAttribute('hidden');
|
|
61
|
+
// Set the width and height as pixels so they can be animated.
|
|
62
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
63
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
64
|
+
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>{
|
|
65
|
+
// After the animations complete, switch back to auto so the content can resize.
|
|
66
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
67
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
68
|
+
}).catch(()=>{});
|
|
69
|
+
} else {
|
|
70
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
71
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
72
|
+
// Force style re-calculation to trigger animations.
|
|
73
|
+
window.getComputedStyle(panel).height;
|
|
74
|
+
// Animate to zero size.
|
|
75
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
76
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
77
|
+
// Wait for animations to apply the hidden attribute.
|
|
78
|
+
Promise.all(panel.getAnimations().map((a)=>a.finished)).then(()=>panel.setAttribute('hidden', 'until-found')).catch(()=>{});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
isExpandedRef.current = state.isExpanded;
|
|
49
82
|
}
|
|
50
83
|
}, [
|
|
51
84
|
isDisabled,
|
|
52
85
|
ref,
|
|
53
86
|
state.isExpanded,
|
|
54
|
-
|
|
87
|
+
isSSR
|
|
55
88
|
]);
|
|
56
89
|
(0, $6wN6e$useEffect)(()=>{
|
|
57
90
|
return ()=>{
|
|
@@ -77,7 +110,7 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
|
|
|
77
110
|
role: 'group',
|
|
78
111
|
'aria-labelledby': triggerId,
|
|
79
112
|
'aria-hidden': !state.isExpanded,
|
|
80
|
-
hidden:
|
|
113
|
+
hidden: isSSR || isDisabled ? isDisabled || !state.isExpanded : undefined
|
|
81
114
|
}
|
|
82
115
|
};
|
|
83
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAAkC;IAClH,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,UAAU,CAAA,GAAA,YAAI;IAClB,IAAI,QAAQ,CAAA,GAAA,eAAO;IAEnB,IAAI,MAAM,CAAA,GAAA,aAAK,EAAiB;IAEhC,IAAI,oBAAoB,CAAA,GAAA,kBAAU,EAAE;QAClC,+DAA+D;QAC/D,IAAI,OAAO,GAAG,sBAAsB;YAClC,IAAI,IAAI,OAAO,EACb,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;QAEvC;QACA,0BAA0B;QAC1B,CAAA,GAAA,gBAAQ,EAAE;YACR,MAAM,MAAM;QACd;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,0DAA0D;IAC1D,CAAA,GAAA,eAAO,EAAE,KAAK,eAAe;IAE7B,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAkB;IAC3C,CAAA,GAAA,sBAAc,EAAE;QACd,kDAAkD;QAClD,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAElC,IAAI,IAAI,OAAO,IAAI,C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QAAQ,GAAG,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,CAAA,IAAK,EAAE,QAAQ,GAClD,IAAI,CAAC,IAAM,MAAM,YAAY,CAAC,UAAU,gBACxC,KAAK,CAAC,KAAO;gBAClB;;YAGF,cAAc,OAAO,GAAG,MAAM,UAAU;QAC1C;IACF,GAAG;QAAC;QAAY;QAAK,MAAM,UAAU;QAAE;KAAM;IAE7C,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;YACL,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAEpC;IACF,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YACX,IAAI;YACJ,iBAAiB,MAAM,UAAU;YACjC,iBAAiB;YACjB,SAAS,CAAC;gBACR,IAAI,CAAC,cAAc,EAAE,WAAW,KAAK,YACnC,MAAM,MAAM;YAEhB;wBACA;YACA,cAAa,CAAC;gBACZ,IAAI,EAAE,WAAW,KAAK,cAAc,CAAC,YACnC,MAAM,MAAM;YAEhB;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,eAAe,CAAC,MAAM,UAAU;YAChC,QAAQ,AAAC,SAAS,aAAe,cAAc,CAAC,MAAM,UAAU,GAAI;QACtE;IACF;AACF","sources":["packages/@react-aria/disclosure/src/useDisclosure.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the 'License');\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DisclosureState} from '@react-stately/disclosure';\nimport {flushSync} from 'react-dom';\nimport {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';\nimport {useEvent, useId, useLayoutEffect} from '@react-aria/utils';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport interface AriaDisclosureProps {\n /** Whether the disclosure is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the disclosure's expanded state changes. */\n onExpandedChange?: (isExpanded: boolean) => void,\n /** Whether the disclosure is expanded (controlled). */\n isExpanded?: boolean,\n /** Whether the disclosure is expanded by default (uncontrolled). */\n defaultExpanded?: boolean\n}\n\nexport interface DisclosureAria {\n /** Props for the disclosure button. */\n buttonProps: AriaButtonProps,\n /** Props for the disclosure panel. */\n panelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a disclosure component.\n * @param props - Props for the disclosure.\n * @param state - State for the disclosure, as returned by `useDisclosureState`.\n * @param ref - A ref for the disclosure panel.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let panelId = useId();\n let isSSR = useIsSSR();\n\n let raf = useRef<number | null>(null);\n\n let handleBeforeMatch = useCallback(() => {\n // Wait a frame to revert browser's removal of hidden attribute\n raf.current = requestAnimationFrame(() => {\n if (ref.current) {\n ref.current.setAttribute('hidden', 'until-found');\n }\n });\n // Force sync state update\n flushSync(() => {\n state.toggle();\n });\n }, [ref, state]);\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', handleBeforeMatch);\n\n let isExpandedRef = useRef<boolean | null>(null);\n useLayoutEffect(() => {\n // Cancel any pending RAF to prevent stale updates\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n if (ref.current && !isDisabled && !isSSR) {\n let panel = ref.current;\n\n if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {\n // On initial render (and in tests), set attributes without animation.\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n } else {\n panel.setAttribute('hidden', 'until-found');\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n }\n } else if (state.isExpanded !== isExpandedRef.current) {\n if (state.isExpanded) {\n panel.removeAttribute('hidden');\n\n // Set the width and height as pixels so they can be animated.\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => {\n // After the animations complete, switch back to auto so the content can resize.\n panel.style.setProperty('--disclosure-panel-width', 'auto');\n panel.style.setProperty('--disclosure-panel-height', 'auto');\n })\n .catch(() => {});\n } else {\n panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');\n panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');\n\n // Force style re-calculation to trigger animations.\n window.getComputedStyle(panel).height;\n\n // Animate to zero size.\n panel.style.setProperty('--disclosure-panel-width', '0px');\n panel.style.setProperty('--disclosure-panel-height', '0px');\n\n // Wait for animations to apply the hidden attribute.\n Promise.all(panel.getAnimations().map(a => a.finished))\n .then(() => panel.setAttribute('hidden', 'until-found'))\n .catch(() => {});\n }\n }\n\n isExpandedRef.current = state.isExpanded;\n }\n }, [isDisabled, ref, state.isExpanded, isSSR]);\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': panelId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onPressStart(e) {\n if (e.pointerType === 'keyboard' && !isDisabled) {\n state.toggle();\n }\n }\n },\n panelProps: {\n id: panelId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n 'aria-hidden': !state.isExpanded,\n hidden: (isSSR || isDisabled) ? (isDisabled || !state.isExpanded) : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/disclosure",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@react-aria/ssr": "^3.9.10",
|
|
30
|
-
"@react-aria/utils": "^3.
|
|
31
|
-
"@react-stately/disclosure": "^3.0.
|
|
32
|
-
"@react-types/button": "^3.14.
|
|
30
|
+
"@react-aria/utils": "^3.31.0",
|
|
31
|
+
"@react-stately/disclosure": "^3.0.8",
|
|
32
|
+
"@react-types/button": "^3.14.1",
|
|
33
33
|
"@swc/helpers": "^0.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
|
|
43
43
|
}
|
package/src/.DS_Store
ADDED
|
Binary file
|
package/src/useDisclosure.ts
CHANGED
|
@@ -41,14 +41,13 @@ export interface DisclosureAria {
|
|
|
41
41
|
* @param state - State for the disclosure, as returned by `useDisclosureState`.
|
|
42
42
|
* @param ref - A ref for the disclosure panel.
|
|
43
43
|
*/
|
|
44
|
-
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<
|
|
44
|
+
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<HTMLElement | null>): DisclosureAria {
|
|
45
45
|
let {
|
|
46
46
|
isDisabled
|
|
47
47
|
} = props;
|
|
48
48
|
let triggerId = useId();
|
|
49
49
|
let panelId = useId();
|
|
50
50
|
let isSSR = useIsSSR();
|
|
51
|
-
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
|
|
52
51
|
|
|
53
52
|
let raf = useRef<number | null>(null);
|
|
54
53
|
|
|
@@ -66,22 +65,64 @@ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState
|
|
|
66
65
|
}, [ref, state]);
|
|
67
66
|
|
|
68
67
|
// @ts-ignore https://github.com/facebook/react/pull/24741
|
|
69
|
-
useEvent(ref, 'beforematch',
|
|
68
|
+
useEvent(ref, 'beforematch', handleBeforeMatch);
|
|
70
69
|
|
|
70
|
+
let isExpandedRef = useRef<boolean | null>(null);
|
|
71
71
|
useLayoutEffect(() => {
|
|
72
72
|
// Cancel any pending RAF to prevent stale updates
|
|
73
73
|
if (raf.current) {
|
|
74
74
|
cancelAnimationFrame(raf.current);
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
if (ref.current && !isDisabled && !isSSR) {
|
|
77
|
+
let panel = ref.current;
|
|
78
|
+
|
|
79
|
+
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
|
|
80
|
+
// On initial render (and in tests), set attributes without animation.
|
|
81
|
+
if (state.isExpanded) {
|
|
82
|
+
panel.removeAttribute('hidden');
|
|
83
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
84
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
85
|
+
} else {
|
|
86
|
+
panel.setAttribute('hidden', 'until-found');
|
|
87
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
88
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
89
|
+
}
|
|
90
|
+
} else if (state.isExpanded !== isExpandedRef.current) {
|
|
91
|
+
if (state.isExpanded) {
|
|
92
|
+
panel.removeAttribute('hidden');
|
|
93
|
+
|
|
94
|
+
// Set the width and height as pixels so they can be animated.
|
|
95
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
96
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
97
|
+
|
|
98
|
+
Promise.all(panel.getAnimations().map(a => a.finished))
|
|
99
|
+
.then(() => {
|
|
100
|
+
// After the animations complete, switch back to auto so the content can resize.
|
|
101
|
+
panel.style.setProperty('--disclosure-panel-width', 'auto');
|
|
102
|
+
panel.style.setProperty('--disclosure-panel-height', 'auto');
|
|
103
|
+
})
|
|
104
|
+
.catch(() => {});
|
|
105
|
+
} else {
|
|
106
|
+
panel.style.setProperty('--disclosure-panel-width', panel.scrollWidth + 'px');
|
|
107
|
+
panel.style.setProperty('--disclosure-panel-height', panel.scrollHeight + 'px');
|
|
108
|
+
|
|
109
|
+
// Force style re-calculation to trigger animations.
|
|
110
|
+
window.getComputedStyle(panel).height;
|
|
111
|
+
|
|
112
|
+
// Animate to zero size.
|
|
113
|
+
panel.style.setProperty('--disclosure-panel-width', '0px');
|
|
114
|
+
panel.style.setProperty('--disclosure-panel-height', '0px');
|
|
115
|
+
|
|
116
|
+
// Wait for animations to apply the hidden attribute.
|
|
117
|
+
Promise.all(panel.getAnimations().map(a => a.finished))
|
|
118
|
+
.then(() => panel.setAttribute('hidden', 'until-found'))
|
|
119
|
+
.catch(() => {});
|
|
120
|
+
}
|
|
82
121
|
}
|
|
122
|
+
|
|
123
|
+
isExpandedRef.current = state.isExpanded;
|
|
83
124
|
}
|
|
84
|
-
}, [isDisabled, ref, state.isExpanded,
|
|
125
|
+
}, [isDisabled, ref, state.isExpanded, isSSR]);
|
|
85
126
|
|
|
86
127
|
useEffect(() => {
|
|
87
128
|
return () => {
|
|
@@ -114,7 +155,7 @@ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState
|
|
|
114
155
|
role: 'group',
|
|
115
156
|
'aria-labelledby': triggerId,
|
|
116
157
|
'aria-hidden': !state.isExpanded,
|
|
117
|
-
hidden:
|
|
158
|
+
hidden: (isSSR || isDisabled) ? (isDisabled || !state.isExpanded) : undefined
|
|
118
159
|
}
|
|
119
160
|
};
|
|
120
161
|
}
|