Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-aria/disclosure

Package Overview
Dependencies
Maintainers
2
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/disclosure - npm Package Compare versions

Comparing version 3.0.0-nightly-69109f003-241018 to 3.0.0-nightly-93c26d8bd-241025

2

dist/types.d.ts

@@ -26,4 +26,4 @@ import { AriaButtonProps } from "@react-types/button";

*/
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria;
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<Element | null>): DisclosureAria;
//# sourceMappingURL=types.d.ts.map

@@ -0,1 +1,2 @@

var $l3cx6$reactdom = require("react-dom");
var $l3cx6$react = require("react");

@@ -24,2 +25,3 @@ var $l3cx6$reactariautils = require("@react-aria/utils");

function $ef53cd1bcef2de68$export$6e3e27031a30522f(props, state, ref) {

@@ -29,10 +31,25 @@ let { isDisabled: isDisabled } = props;

let contentId = (0, $l3cx6$reactariautils.useId)();
let isControlled = props.isExpanded !== undefined;
let isSSR = (0, $l3cx6$reactariassr.useIsSSR)();
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
let raf = (0, $l3cx6$react.useRef)(null);
let handleBeforeMatch = (0, $l3cx6$react.useCallback)(()=>{
// Wait a frame to revert browser's removal of hidden attribute
raf.current = requestAnimationFrame(()=>{
if (ref.current) ref.current.setAttribute('hidden', 'until-found');
});
// Force sync state update
(0, $l3cx6$reactdom.flushSync)(()=>{
state.toggle();
});
}, [
ref,
state
]);
// @ts-ignore https://github.com/facebook/react/pull/24741
(0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
(0, $l3cx6$react.useEffect)(()=>{
(0, $l3cx6$reactariautils.useEvent)(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
(0, $l3cx6$reactariautils.useLayoutEffect)(()=>{
// Cancel any pending RAF to prevent stale updates
if (raf.current) cancelAnimationFrame(raf.current);
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
if (supportsBeforeMatch && ref.current && !isDisabled) {
if (state.isExpanded) ref.current.removeAttribute('hidden');

@@ -42,9 +59,12 @@ else ref.current.setAttribute('hidden', 'until-found');

}, [
isControlled,
isDisabled,
ref,
props.isExpanded,
state,
supportsBeforeMatch,
isDisabled
state.isExpanded,
supportsBeforeMatch
]);
(0, $l3cx6$react.useEffect)(()=>{
return ()=>{
if (raf.current) cancelAnimationFrame(raf.current);
};
}, []);
return {

@@ -71,3 +91,3 @@ buttonProps: {

'aria-labelledby': triggerId,
hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
hidden: supportsBeforeMatch ? true : !state.isExpanded
}

@@ -74,0 +94,0 @@ };

@@ -1,3 +0,4 @@

import {useEffect as $6wN6e$useEffect} from "react";
import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent} from "@react-aria/utils";
import {flushSync as $6wN6e$flushSync} from "react-dom";
import {useRef as $6wN6e$useRef, useCallback as $6wN6e$useCallback, useEffect as $6wN6e$useEffect} from "react";
import {useId as $6wN6e$useId, useEvent as $6wN6e$useEvent, useLayoutEffect as $6wN6e$useLayoutEffect} from "@react-aria/utils";
import {useIsSSR as $6wN6e$useIsSSR} from "@react-aria/ssr";

@@ -18,2 +19,3 @@

function $5e910fae8e128ead$export$6e3e27031a30522f(props, state, ref) {

@@ -23,10 +25,25 @@ let { isDisabled: isDisabled } = props;

let contentId = (0, $6wN6e$useId)();
let isControlled = props.isExpanded !== undefined;
let isSSR = (0, $6wN6e$useIsSSR)();
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
let raf = (0, $6wN6e$useRef)(null);
let handleBeforeMatch = (0, $6wN6e$useCallback)(()=>{
// Wait a frame to revert browser's removal of hidden attribute
raf.current = requestAnimationFrame(()=>{
if (ref.current) ref.current.setAttribute('hidden', 'until-found');
});
// Force sync state update
(0, $6wN6e$flushSync)(()=>{
state.toggle();
});
}, [
ref,
state
]);
// @ts-ignore https://github.com/facebook/react/pull/24741
(0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch && !isControlled ? ()=>state.expand() : null);
(0, $6wN6e$useEffect)(()=>{
(0, $6wN6e$useEvent)(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
(0, $6wN6e$useLayoutEffect)(()=>{
// Cancel any pending RAF to prevent stale updates
if (raf.current) cancelAnimationFrame(raf.current);
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
if (supportsBeforeMatch && (ref === null || ref === void 0 ? void 0 : ref.current) && !isControlled && !isDisabled) {
if (supportsBeforeMatch && ref.current && !isDisabled) {
if (state.isExpanded) ref.current.removeAttribute('hidden');

@@ -36,9 +53,12 @@ else ref.current.setAttribute('hidden', 'until-found');

}, [
isControlled,
isDisabled,
ref,
props.isExpanded,
state,
supportsBeforeMatch,
isDisabled
state.isExpanded,
supportsBeforeMatch
]);
(0, $6wN6e$useEffect)(()=>{
return ()=>{
if (raf.current) cancelAnimationFrame(raf.current);
};
}, []);
return {

@@ -65,3 +85,3 @@ buttonProps: {

'aria-labelledby': triggerId,
hidden: !supportsBeforeMatch || isControlled ? !state.isExpanded : true
hidden: supportsBeforeMatch ? true : !state.isExpanded
}

@@ -68,0 +88,0 @@ };

{
"name": "@react-aria/disclosure",
"version": "3.0.0-nightly-69109f003-241018",
"version": "3.0.0-nightly-93c26d8bd-241025",
"description": "Spectrum UI components in React",

@@ -25,11 +25,11 @@ "license": "Apache-2.0",

"dependencies": {
"@react-aria/button": "^3.0.0-nightly-69109f003-241018",
"@react-aria/selection": "^3.0.0-nightly-69109f003-241018",
"@react-aria/ssr": "^3.0.0-nightly-69109f003-241018",
"@react-aria/utils": "^3.0.0-nightly-69109f003-241018",
"@react-stately/disclosure": "3.0.0-nightly-69109f003-241018",
"@react-stately/toggle": "^3.0.0-nightly-69109f003-241018",
"@react-stately/tree": "^3.0.0-nightly-69109f003-241018",
"@react-types/button": "^3.0.0-nightly-69109f003-241018",
"@react-types/shared": "^3.0.0-nightly-69109f003-241018",
"@react-aria/button": "^3.0.0-nightly-93c26d8bd-241025",
"@react-aria/selection": "^3.0.0-nightly-93c26d8bd-241025",
"@react-aria/ssr": "^3.0.0-nightly-93c26d8bd-241025",
"@react-aria/utils": "^3.0.0-nightly-93c26d8bd-241025",
"@react-stately/disclosure": "3.0.0-nightly-93c26d8bd-241025",
"@react-stately/toggle": "^3.0.0-nightly-93c26d8bd-241025",
"@react-stately/tree": "^3.0.0-nightly-93c26d8bd-241025",
"@react-types/button": "^3.0.0-nightly-93c26d8bd-241025",
"@react-types/shared": "^3.0.0-nightly-93c26d8bd-241025",
"@swc/helpers": "^0.5.0"

@@ -36,0 +36,0 @@ },

@@ -15,4 +15,5 @@ /*

import {DisclosureState} from '@react-stately/disclosure';
import {HTMLAttributes, RefObject, useEffect} from 'react';
import {useEvent, useId} from '@react-aria/utils';
import {flushSync} from 'react-dom';
import {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';
import {useEvent, useId, useLayoutEffect} from '@react-aria/utils';
import {useIsSSR} from '@react-aria/ssr';

@@ -44,3 +45,3 @@

*/
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref: RefObject<Element | null>): DisclosureAria {
let {

@@ -51,12 +52,30 @@ isDisabled

let contentId = useId();
let isControlled = props.isExpanded !== undefined;
let isSSR = useIsSSR();
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;
let raf = useRef<number | null>(null);
let handleBeforeMatch = useCallback(() => {
// Wait a frame to revert browser's removal of hidden attribute
raf.current = requestAnimationFrame(() => {
if (ref.current) {
ref.current.setAttribute('hidden', 'until-found');
}
});
// Force sync state update
flushSync(() => {
state.toggle();
});
}, [ref, state]);
// @ts-ignore https://github.com/facebook/react/pull/24741
useEvent(ref, 'beforematch', supportsBeforeMatch && !isControlled ? () => state.expand() : null);
useEvent(ref, 'beforematch', supportsBeforeMatch ? handleBeforeMatch : null);
useEffect(() => {
useLayoutEffect(() => {
// Cancel any pending RAF to prevent stale updates
if (raf.current) {
cancelAnimationFrame(raf.current);
}
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {
if (supportsBeforeMatch && ref.current && !isDisabled) {
if (state.isExpanded) {

@@ -68,4 +87,12 @@ ref.current.removeAttribute('hidden');

}
}, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);
}, [isDisabled, ref, state.isExpanded, supportsBeforeMatch]);
useEffect(() => {
return () => {
if (raf.current) {
cancelAnimationFrame(raf.current);
}
};
}, []);
return {

@@ -94,5 +121,5 @@ buttonProps: {

'aria-labelledby': triggerId,
hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true
hidden: supportsBeforeMatch ? true : !state.isExpanded
}
};
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc