@react-aria/disclosure 3.0.0-nightly-0ddbe6f95-241021 → 3.0.0-nightly-68e305768-241023

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 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 content.
25
25
  */
26
- export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria;
26
+ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<Element | null>): DisclosureAria;
27
27
 
28
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";;;AAkBA;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,CAAC,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,GAAG,cAAc,CAkDjI","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"}
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,OAAO,GAAG,IAAI,CAAC,GAAG,cAAc,CA4EhI","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"}
@@ -1,3 +1,4 @@
1
+ var $l3cx6$reactdom = require("react-dom");
1
2
  var $l3cx6$react = require("react");
2
3
  var $l3cx6$reactariautils = require("@react-aria/utils");
3
4
  var $l3cx6$reactariassr = require("@react-aria/ssr");
@@ -21,29 +22,48 @@ $parcel$export(module.exports, "useDisclosure", () => $ef53cd1bcef2de68$export$6
21
22
  */
22
23
 
23
24
 
25
+
24
26
  function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
25
27
  let { isDisabled: isDisabled } = props;
26
28
  let triggerId = (0, $l3cx6$reactariautils.useId)();
27
29
  let contentId = (0, $l3cx6$reactariautils.useId)();
28
- let isControlled = props.isExpanded !== undefined;
29
30
  let isSSR = (0, $l3cx6$reactariassr.useIsSSR)();
30
31
  let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
32
+ let raf = (0, $l3cx6$react.useRef)(null);
33
+ let handleBeforeMatch = (0, $l3cx6$react.useCallback)(()=>{
34
+ // Wait a frame to revert browser's removal of hidden attribute
35
+ raf.current = requestAnimationFrame(()=>{
36
+ if (ref.current) ref.current.setAttribute('hidden', 'until-found');
37
+ });
38
+ // Force sync state update
39
+ (0, $l3cx6$reactdom.flushSync)(()=>{
40
+ state.toggle();
41
+ });
42
+ }, [
43
+ ref,
44
+ state
45
+ ]);
31
46
  // @ts-ignore https://github.com/facebook/react/pull/24741
32
- (0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
33
- (0, $l3cx6$react.useEffect)(()=>{
47
+ (0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
48
+ (0, $l3cx6$reactariautils.useLayoutEffect)(()=>{
49
+ // Cancel any pending RAF to prevent stale updates
50
+ if (raf.current) cancelAnimationFrame(raf.current);
34
51
  // Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
35
- if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
52
+ if (supportsBeforeMatch && ref.current && !isDisabled) {
36
53
  if (state.isExpanded) ref.current.removeAttribute('hidden');
37
54
  else ref.current.setAttribute('hidden', 'until-found');
38
55
  }
39
56
  }, [
40
- isControlled,
57
+ isDisabled,
41
58
  ref,
42
- props.isExpanded,
43
- state,
44
- supportsBeforeMatch,
45
- isDisabled
59
+ state.isExpanded,
60
+ supportsBeforeMatch
46
61
  ]);
62
+ (0, $l3cx6$react.useEffect)(()=>{
63
+ return ()=>{
64
+ if (raf.current) cancelAnimationFrame(raf.current);
65
+ };
66
+ }, []);
47
67
  return {
48
68
  buttonProps: {
49
69
  id: triggerId,
@@ -65,7 +85,7 @@ function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {
65
85
  // This can be overridden at the panel element level.
66
86
  role: 'group',
67
87
  'aria-labelledby': triggerId,
68
- hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
88
+ hidden: supportsBeforeMatch ? true : !state.isExpanded
69
89
  }
70
90
  };
71
91
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAgCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAA+B;IAC/G,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,eAAe,MAAM,UAAU,KAAK;IACxC,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,sBAAsB,CAAC,SAAS,mBAAmB,SAAS,IAAI;IAEpE,0DAA0D;IAC1D,CAAA,GAAA,8BAAO,EAAE,KAAK,eAAe,uBAAuB,CAAC,eAAe,IAAM,MAAM,MAAM,KAAK;IAE3F,CAAA,GAAA,sBAAQ,EAAE;QACR,0FAA0F;QAC1F,IAAI,wBAAuB,gBAAA,0BAAA,IAAK,OAAO,KAAI,CAAC,gBAAgB,CAAC;YAC3D,IAAI,MAAM,UAAU,EAClB,IAAI,OAAO,CAAC,eAAe,CAAC;iBAE5B,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;;IAGzC,GAAG;QAAC;QAAc;QAAK,MAAM,UAAU;QAAE;QAAO;QAAqB;KAAW;IAEhF,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,WAAU,CAAC;gBACT,IAAI,CAAC,cAAe,CAAA,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,GAAE,GAAI;oBACvD,EAAE,cAAc;oBAChB,MAAM,MAAM;gBACd;YACF;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,QAAQ,AAAC,CAAC,uBAAuB,eAAgB,CAAC,MAAM,UAAU,GAAG;QACvE;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 {HTMLAttributes, RefObject, useEffect} from 'react';\nimport {useEvent, useId} 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 content.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let contentId = useId();\n let isControlled = props.isExpanded !== undefined;\n let isSSR = useIsSSR();\n let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);\n\n useEffect(() => {\n // Until React supports hidden=\"until-found\": https://github.com/facebook/react/pull/24741\n if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {\n if (state.isExpanded) {\n ref.current.removeAttribute('hidden');\n } else {\n ref.current.setAttribute('hidden', 'until-found');\n }\n }\n }, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': contentId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onKeyDown(e) {\n if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {\n e.preventDefault();\n state.toggle();\n }\n }\n },\n panelProps: {\n id: contentId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAA8B;IAC9G,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,sBAAsB,CAAC,SAAS,mBAAmB,SAAS,IAAI;IAEpE,IAAI,MAAM,CAAA,GAAA,mBAAK,EAAiB;IAEhC,IAAI,oBAAoB,CAAA,GAAA,wBAAU,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,yBAAQ,EAAE;YACR,MAAM,MAAM;QACd;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,0DAA0D;IAC1D,CAAA,GAAA,8BAAO,EAAE,KAAK,eAAe,sBAAsB,oBAAoB;IAEvE,CAAA,GAAA,qCAAc,EAAE;QACd,kDAAkD;QAClD,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAElC,0FAA0F;QAC1F,IAAI,uBAAuB,IAAI,OAAO,IAAI,CAAC;YACzC,IAAI,MAAM,UAAU,EAClB,IAAI,OAAO,CAAC,eAAe,CAAC;iBAE5B,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;;IAGzC,GAAG;QAAC;QAAY;QAAK,MAAM,UAAU;QAAE;KAAoB;IAE3D,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,WAAU,CAAC;gBACT,IAAI,CAAC,cAAe,CAAA,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,GAAE,GAAI;oBACvD,EAAE,cAAc;oBAChB,MAAM,MAAM;gBACd;YACF;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,QAAQ,sBAAsB,OAAO,CAAC,MAAM,UAAU;QACxD;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 content.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<Element | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let contentId = useId();\n let isSSR = useIsSSR();\n let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;\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', supportsBeforeMatch ? handleBeforeMatch : null);\n\n useLayoutEffect(() => {\n // Cancel any pending RAF to prevent stale updates\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n // Until React supports hidden=\"until-found\": https://github.com/facebook/react/pull/24741\n if (supportsBeforeMatch && ref.current && !isDisabled) {\n if (state.isExpanded) {\n ref.current.removeAttribute('hidden');\n } else {\n ref.current.setAttribute('hidden', 'until-found');\n }\n }\n }, [isDisabled, ref, state.isExpanded, supportsBeforeMatch]);\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': contentId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onKeyDown(e) {\n if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {\n e.preventDefault();\n state.toggle();\n }\n }\n },\n panelProps: {\n id: contentId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n hidden: supportsBeforeMatch ? true : !state.isExpanded\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.main.js.map"}
@@ -1,5 +1,6 @@
1
- import {useEffect as $6wN6e$useEffect} from "react";
2
- import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent} from "@react-aria/utils";
1
+ import {flushSync as $6wN6e$flushSync} from "react-dom";
2
+ import {useRef as $6wN6e$useRef, useCallback as $6wN6e$useCallback, useEffect as $6wN6e$useEffect} from "react";
3
+ import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent, useLayoutEffect as $6wN6e$useLayoutEffect} from "@react-aria/utils";
3
4
  import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
4
5
 
5
6
  /*
@@ -15,29 +16,48 @@ import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
15
16
  */
16
17
 
17
18
 
19
+
18
20
  function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
19
21
  let { isDisabled: isDisabled } = props;
20
22
  let triggerId = (0, $6wN6e$useId)();
21
23
  let contentId = (0, $6wN6e$useId)();
22
- let isControlled = props.isExpanded !== undefined;
23
24
  let isSSR = (0, $6wN6e$useIsSSR)();
24
25
  let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
26
+ let raf = (0, $6wN6e$useRef)(null);
27
+ let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
28
+ // Wait a frame to revert browser's removal of hidden attribute
29
+ raf.current = requestAnimationFrame(()=>{
30
+ if (ref.current) ref.current.setAttribute('hidden', 'until-found');
31
+ });
32
+ // Force sync state update
33
+ (0, $6wN6e$flushSync)(()=>{
34
+ state.toggle();
35
+ });
36
+ }, [
37
+ ref,
38
+ state
39
+ ]);
25
40
  // @ts-ignore https://github.com/facebook/react/pull/24741
26
- (0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
27
- (0, $6wN6e$useEffect)(()=>{
41
+ (0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
42
+ (0, $6wN6e$useLayoutEffect)(()=>{
43
+ // Cancel any pending RAF to prevent stale updates
44
+ if (raf.current) cancelAnimationFrame(raf.current);
28
45
  // Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
29
- if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
46
+ if (supportsBeforeMatch && ref.current && !isDisabled) {
30
47
  if (state.isExpanded) ref.current.removeAttribute('hidden');
31
48
  else ref.current.setAttribute('hidden', 'until-found');
32
49
  }
33
50
  }, [
34
- isControlled,
51
+ isDisabled,
35
52
  ref,
36
- props.isExpanded,
37
- state,
38
- supportsBeforeMatch,
39
- isDisabled
53
+ state.isExpanded,
54
+ supportsBeforeMatch
40
55
  ]);
56
+ (0, $6wN6e$useEffect)(()=>{
57
+ return ()=>{
58
+ if (raf.current) cancelAnimationFrame(raf.current);
59
+ };
60
+ }, []);
41
61
  return {
42
62
  buttonProps: {
43
63
  id: triggerId,
@@ -59,7 +79,7 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
59
79
  // This can be overridden at the panel element level.
60
80
  role: 'group',
61
81
  'aria-labelledby': triggerId,
62
- hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
82
+ hidden: supportsBeforeMatch ? true : !state.isExpanded
63
83
  }
64
84
  };
65
85
  }
@@ -1,5 +1,6 @@
1
- import {useEffect as $6wN6e$useEffect} from "react";
2
- import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent} from "@react-aria/utils";
1
+ import {flushSync as $6wN6e$flushSync} from "react-dom";
2
+ import {useRef as $6wN6e$useRef, useCallback as $6wN6e$useCallback, useEffect as $6wN6e$useEffect} from "react";
3
+ import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent, useLayoutEffect as $6wN6e$useLayoutEffect} from "@react-aria/utils";
3
4
  import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
4
5
 
5
6
  /*
@@ -15,29 +16,48 @@ import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";
15
16
  */
16
17
 
17
18
 
19
+
18
20
  function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
19
21
  let { isDisabled: isDisabled } = props;
20
22
  let triggerId = (0, $6wN6e$useId)();
21
23
  let contentId = (0, $6wN6e$useId)();
22
- let isControlled = props.isExpanded !== undefined;
23
24
  let isSSR = (0, $6wN6e$useIsSSR)();
24
25
  let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
26
+ let raf = (0, $6wN6e$useRef)(null);
27
+ let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
28
+ // Wait a frame to revert browser's removal of hidden attribute
29
+ raf.current = requestAnimationFrame(()=>{
30
+ if (ref.current) ref.current.setAttribute('hidden', 'until-found');
31
+ });
32
+ // Force sync state update
33
+ (0, $6wN6e$flushSync)(()=>{
34
+ state.toggle();
35
+ });
36
+ }, [
37
+ ref,
38
+ state
39
+ ]);
25
40
  // @ts-ignore https://github.com/facebook/react/pull/24741
26
- (0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
27
- (0, $6wN6e$useEffect)(()=>{
41
+ (0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
42
+ (0, $6wN6e$useLayoutEffect)(()=>{
43
+ // Cancel any pending RAF to prevent stale updates
44
+ if (raf.current) cancelAnimationFrame(raf.current);
28
45
  // Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
29
- if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
46
+ if (supportsBeforeMatch && ref.current && !isDisabled) {
30
47
  if (state.isExpanded) ref.current.removeAttribute('hidden');
31
48
  else ref.current.setAttribute('hidden', 'until-found');
32
49
  }
33
50
  }, [
34
- isControlled,
51
+ isDisabled,
35
52
  ref,
36
- props.isExpanded,
37
- state,
38
- supportsBeforeMatch,
39
- isDisabled
53
+ state.isExpanded,
54
+ supportsBeforeMatch
40
55
  ]);
56
+ (0, $6wN6e$useEffect)(()=>{
57
+ return ()=>{
58
+ if (raf.current) cancelAnimationFrame(raf.current);
59
+ };
60
+ }, []);
41
61
  return {
42
62
  buttonProps: {
43
63
  id: triggerId,
@@ -59,7 +79,7 @@ function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {
59
79
  // This can be overridden at the panel element level.
60
80
  role: 'group',
61
81
  'aria-labelledby': triggerId,
62
- hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
82
+ hidden: supportsBeforeMatch ? true : !state.isExpanded
63
83
  }
64
84
  };
65
85
  }
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAgCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAA+B;IAC/G,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,eAAe,MAAM,UAAU,KAAK;IACxC,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,sBAAsB,CAAC,SAAS,mBAAmB,SAAS,IAAI;IAEpE,0DAA0D;IAC1D,CAAA,GAAA,eAAO,EAAE,KAAK,eAAe,uBAAuB,CAAC,eAAe,IAAM,MAAM,MAAM,KAAK;IAE3F,CAAA,GAAA,gBAAQ,EAAE;QACR,0FAA0F;QAC1F,IAAI,wBAAuB,gBAAA,0BAAA,IAAK,OAAO,KAAI,CAAC,gBAAgB,CAAC;YAC3D,IAAI,MAAM,UAAU,EAClB,IAAI,OAAO,CAAC,eAAe,CAAC;iBAE5B,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;;IAGzC,GAAG;QAAC;QAAc;QAAK,MAAM,UAAU;QAAE;QAAO;QAAqB;KAAW;IAEhF,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,WAAU,CAAC;gBACT,IAAI,CAAC,cAAe,CAAA,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,GAAE,GAAI;oBACvD,EAAE,cAAc;oBAChB,MAAM,MAAM;gBACd;YACF;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,QAAQ,AAAC,CAAC,uBAAuB,eAAgB,CAAC,MAAM,UAAU,GAAG;QACvE;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 {HTMLAttributes, RefObject, useEffect} from 'react';\nimport {useEvent, useId} 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 content.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let contentId = useId();\n let isControlled = props.isExpanded !== undefined;\n let isSSR = useIsSSR();\n let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;\n\n // @ts-ignore https://github.com/facebook/react/pull/24741\n useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);\n\n useEffect(() => {\n // Until React supports hidden=\"until-found\": https://github.com/facebook/react/pull/24741\n if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {\n if (state.isExpanded) {\n ref.current.removeAttribute('hidden');\n } else {\n ref.current.setAttribute('hidden', 'until-found');\n }\n }\n }, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);\n\n return {\n buttonProps: {\n id: triggerId,\n 'aria-expanded': state.isExpanded,\n 'aria-controls': contentId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onKeyDown(e) {\n if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {\n e.preventDefault();\n state.toggle();\n }\n }\n },\n panelProps: {\n id: contentId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true\n }\n };\n}\n"],"names":[],"version":3,"file":"useDisclosure.module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAc,KAA0B,EAAE,KAAsB,EAAE,GAA8B;IAC9G,IAAI,cACF,UAAU,EACX,GAAG;IACJ,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,sBAAsB,CAAC,SAAS,mBAAmB,SAAS,IAAI;IAEpE,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,sBAAsB,oBAAoB;IAEvE,CAAA,GAAA,sBAAc,EAAE;QACd,kDAAkD;QAClD,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAElC,0FAA0F;QAC1F,IAAI,uBAAuB,IAAI,OAAO,IAAI,CAAC;YACzC,IAAI,MAAM,UAAU,EAClB,IAAI,OAAO,CAAC,eAAe,CAAC;iBAE5B,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU;;IAGzC,GAAG;QAAC;QAAY;QAAK,MAAM,UAAU;QAAE;KAAoB;IAE3D,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,WAAU,CAAC;gBACT,IAAI,CAAC,cAAe,CAAA,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,GAAE,GAAI;oBACvD,EAAE,cAAc;oBAChB,MAAM,MAAM;gBACd;YACF;QACF;QACA,YAAY;YACV,IAAI;YACJ,qDAAqD;YACrD,MAAM;YACN,mBAAmB;YACnB,QAAQ,sBAAsB,OAAO,CAAC,MAAM,UAAU;QACxD;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 content.\n */\nexport function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<Element | null>): DisclosureAria {\n let {\n isDisabled\n } = props;\n let triggerId = useId();\n let contentId = useId();\n let isSSR = useIsSSR();\n let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;\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', supportsBeforeMatch ? handleBeforeMatch : null);\n\n useLayoutEffect(() => {\n // Cancel any pending RAF to prevent stale updates\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n // Until React supports hidden=\"until-found\": https://github.com/facebook/react/pull/24741\n if (supportsBeforeMatch && ref.current && !isDisabled) {\n if (state.isExpanded) {\n ref.current.removeAttribute('hidden');\n } else {\n ref.current.setAttribute('hidden', 'until-found');\n }\n }\n }, [isDisabled, ref, state.isExpanded, supportsBeforeMatch]);\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': contentId,\n onPress: (e) => {\n if (!isDisabled && e.pointerType !== 'keyboard') {\n state.toggle();\n }\n },\n isDisabled,\n onKeyDown(e) {\n if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {\n e.preventDefault();\n state.toggle();\n }\n }\n },\n panelProps: {\n id: contentId,\n // This can be overridden at the panel element level.\n role: 'group',\n 'aria-labelledby': triggerId,\n hidden: supportsBeforeMatch ? true : !state.isExpanded\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.0-nightly-0ddbe6f95-241021",
3
+ "version": "3.0.0-nightly-68e305768-241023",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,15 +22,15 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/button": "^3.0.0-nightly-0ddbe6f95-241021",
26
- "@react-aria/selection": "^3.0.0-nightly-0ddbe6f95-241021",
27
- "@react-aria/ssr": "^3.0.0-nightly-0ddbe6f95-241021",
28
- "@react-aria/utils": "^3.0.0-nightly-0ddbe6f95-241021",
29
- "@react-stately/disclosure": "3.0.0-nightly-0ddbe6f95-241021",
30
- "@react-stately/toggle": "^3.0.0-nightly-0ddbe6f95-241021",
31
- "@react-stately/tree": "^3.0.0-nightly-0ddbe6f95-241021",
32
- "@react-types/button": "^3.0.0-nightly-0ddbe6f95-241021",
33
- "@react-types/shared": "^3.0.0-nightly-0ddbe6f95-241021",
25
+ "@react-aria/button": "^3.0.0-nightly-68e305768-241023",
26
+ "@react-aria/selection": "^3.0.0-nightly-68e305768-241023",
27
+ "@react-aria/ssr": "^3.0.0-nightly-68e305768-241023",
28
+ "@react-aria/utils": "^3.0.0-nightly-68e305768-241023",
29
+ "@react-stately/disclosure": "3.0.0-nightly-68e305768-241023",
30
+ "@react-stately/toggle": "^3.0.0-nightly-68e305768-241023",
31
+ "@react-stately/tree": "^3.0.0-nightly-68e305768-241023",
32
+ "@react-types/button": "^3.0.0-nightly-68e305768-241023",
33
+ "@react-types/shared": "^3.0.0-nightly-68e305768-241023",
34
34
  "@swc/helpers": "^0.5.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -12,8 +12,9 @@
12
12
 
13
13
  import {AriaButtonProps} from '@react-types/button';
14
14
  import {DisclosureState} from '@react-stately/disclosure';
15
- import {HTMLAttributes, RefObject, useEffect} from 'react';
16
- import {useEvent, useId} from '@react-aria/utils';
15
+ import {flushSync} from 'react-dom';
16
+ import {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';
17
+ import {useEvent, useId, useLayoutEffect} from '@react-aria/utils';
17
18
  import {useIsSSR} from '@react-aria/ssr';
18
19
 
19
20
  export interface AriaDisclosureProps {
@@ -40,29 +41,55 @@ export interface DisclosureAria {
40
41
  * @param state - State for the disclosure, as returned by `useDisclosureState`.
41
42
  * @param ref - A ref for the disclosure content.
42
43
  */
43
- export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {
44
+ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<Element | null>): DisclosureAria {
44
45
  let {
45
46
  isDisabled
46
47
  } = props;
47
48
  let triggerId = useId();
48
49
  let contentId = useId();
49
- let isControlled = props.isExpanded !== undefined;
50
50
  let isSSR = useIsSSR();
51
51
  let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
52
52
 
53
+ let raf = useRef<number | null>(null);
54
+
55
+ let handleBeforeMatch = useCallback(() => {
56
+ // Wait a frame to revert browser's removal of hidden attribute
57
+ raf.current = requestAnimationFrame(() => {
58
+ if (ref.current) {
59
+ ref.current.setAttribute('hidden', 'until-found');
60
+ }
61
+ });
62
+ // Force sync state update
63
+ flushSync(() => {
64
+ state.toggle();
65
+ });
66
+ }, [ref, state]);
67
+
53
68
  // @ts-ignore https://github.com/facebook/react/pull/24741
54
- useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);
69
+ useEvent(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
55
70
 
56
- useEffect(() => {
71
+ useLayoutEffect(() => {
72
+ // Cancel any pending RAF to prevent stale updates
73
+ if (raf.current) {
74
+ cancelAnimationFrame(raf.current);
75
+ }
57
76
  // Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
58
- if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {
77
+ if (supportsBeforeMatch && ref.current && !isDisabled) {
59
78
  if (state.isExpanded) {
60
79
  ref.current.removeAttribute('hidden');
61
80
  } else {
62
81
  ref.current.setAttribute('hidden', 'until-found');
63
82
  }
64
83
  }
65
- }, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);
84
+ }, [isDisabled, ref, state.isExpanded, supportsBeforeMatch]);
85
+
86
+ useEffect(() => {
87
+ return () => {
88
+ if (raf.current) {
89
+ cancelAnimationFrame(raf.current);
90
+ }
91
+ };
92
+ }, []);
66
93
 
67
94
  return {
68
95
  buttonProps: {
@@ -87,7 +114,7 @@ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState
87
114
  // This can be overridden at the panel element level.
88
115
  role: 'group',
89
116
  'aria-labelledby': triggerId,
90
- hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true
117
+ hidden: supportsBeforeMatch ? true : !state.isExpanded
91
118
  }
92
119
  };
93
120
  }