Skip to content

Commit 01e36ac

Browse files
committed
extend starting status
1 parent c49603c commit 01e36ac

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

docs/src/app/(private)/experiments/collapsible/plain.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
width: 100%;
4242

4343
height: var(--collapsible-panel-height);
44-
opacity: 1;
44+
/* opacity: 1;*/
4545

4646
transition:
4747
height var(--duration) ease-out,

docs/src/app/(private)/experiments/collapsible/plain.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ function PlainCollapsible(props: { defaultOpen?: boolean; keepMounted?: boolean
7777
if (!shouldCancelInitialOpenTransitionRef.current && !keepMounted) {
7878
// the closed transition styles must be set here to transition the first
7979
// opening transition when the panel is BOTH initially closed AND `keepMounted={false}`
80-
console.log('handlePanelRef setting opacity 0');
81-
element.style.opacity = '0';
80+
// console.log('handlePanelRef setting opacity 0');
81+
// element.style.opacity = '0';
8282

8383
setHeightAndRemoveDisplayProperty(element);
8484

8585
// after setHeight() all the transition properties need to be removed
86-
console.log('handlePanelRef unsetting inline opacity');
87-
element.style.removeProperty('opacity');
86+
// console.log('handlePanelRef unsetting inline opacity');
87+
// element.style.removeProperty('opacity');
8888
} else {
8989
setHeightAndRemoveDisplayProperty(element);
9090
}
@@ -95,9 +95,11 @@ function PlainCollapsible(props: { defaultOpen?: boolean; keepMounted?: boolean
9595
}
9696

9797
requestAnimationFrame(() => {
98-
setTimeout(() => {
99-
element.style.removeProperty('transition-duration');
100-
shouldCancelInitialOpenTransitionRef.current = false;
98+
shouldCancelInitialOpenTransitionRef.current = false;
99+
requestAnimationFrame(() => {
100+
setTimeout(() => {
101+
element.style.removeProperty('transition-duration');
102+
});
101103
});
102104
});
103105
});
@@ -182,8 +184,8 @@ function PlainCollapsible(props: { defaultOpen?: boolean; keepMounted?: boolean
182184
// the closed transition styles must be set here to transition all opening
183185
// transitions except the first one when `keepMounted={false}`
184186
if (!shouldCancelInitialOpenTransitionRef.current) {
185-
console.log('useEnhancedEffect setting opacity 0');
186-
panel.style.opacity = '0';
187+
// console.log('useEnhancedEffect setting opacity 0');
188+
// panel.style.opacity = '0';
187189
}
188190

189191
requestAnimationFrame(() => {
@@ -195,8 +197,8 @@ function PlainCollapsible(props: { defaultOpen?: boolean; keepMounted?: boolean
195197

196198
if (!shouldCancelInitialOpenTransitionRef.current) {
197199
// remove all the transition properties that were just manually applied
198-
console.log('useEnhancedEffect unsetting inline opacity');
199-
panel.style.removeProperty('opacity');
200+
// console.log('useEnhancedEffect unsetting inline opacity');
201+
// panel.style.removeProperty('opacity');
200202
}
201203

202204
setHeight(panel.scrollHeight);

packages/react/src/utils/useTransitionStatus.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as React from 'react';
33
import { useEnhancedEffect } from './useEnhancedEffect';
44

5-
export type TransitionStatus = 'starting' | 'ending' | undefined;
5+
export type TransitionStatus = 'starting' | 'ending' | 'idle' | undefined;
66

77
/**
88
* Provides a status string for CSS animations.
@@ -30,15 +30,18 @@ export function useTransitionStatus(open: boolean) {
3030
if (!open) {
3131
return undefined;
3232
}
33+
if (open && mounted && transitionStatus !== 'idle') {
34+
setTransitionStatus('starting');
35+
}
3336

3437
const frame = requestAnimationFrame(() => {
35-
setTransitionStatus(undefined);
38+
setTransitionStatus('idle');
3639
});
3740

3841
return () => {
3942
cancelAnimationFrame(frame);
4043
};
41-
}, [open]);
44+
}, [open, mounted, setTransitionStatus, transitionStatus]);
4245

4346
return React.useMemo(
4447
() => ({

0 commit comments

Comments
 (0)