|
1 | 1 | 'use client'; |
2 | 2 | import * as React from 'react'; |
3 | 3 | import { InteractionType } from '@base-ui/utils/useEnhancedClickHandler'; |
| 4 | +import { useIsoLayoutEffect } from '@base-ui/utils/useIsoLayoutEffect'; |
4 | 5 | import { FloatingFocusManager } from '../../floating-ui-react'; |
5 | 6 | import { useDialogRootContext } from '../root/DialogRootContext'; |
| 7 | +import { useDrawerRootContext } from '../../drawer/root/DrawerRootContext'; |
6 | 8 | import { useRenderElement } from '../../utils/useRenderElement'; |
7 | 9 | import { type BaseUIComponentProps } from '../../utils/types'; |
8 | 10 | import { type TransitionStatus } from '../../utils/useTransitionStatus'; |
@@ -50,9 +52,29 @@ export const DialogPopup = React.forwardRef(function DialogPopup( |
50 | 52 | const titleElementId = store.useState('titleElementId'); |
51 | 53 | const transitionStatus = store.useState('transitionStatus'); |
52 | 54 | const role = store.useState('role'); |
| 55 | + const drawerRootContext = useDrawerRootContext(true); |
| 56 | + const lastReportedOpenRef = React.useRef(false); |
53 | 57 |
|
54 | 58 | useDialogPortalContext(); |
55 | 59 |
|
| 60 | + useIsoLayoutEffect(() => { |
| 61 | + if (!drawerRootContext) { |
| 62 | + return undefined; |
| 63 | + } |
| 64 | + |
| 65 | + if (lastReportedOpenRef.current !== open) { |
| 66 | + drawerRootContext.onNonDrawerDialogOpenChange(open ? 1 : -1); |
| 67 | + lastReportedOpenRef.current = open; |
| 68 | + } |
| 69 | + |
| 70 | + return () => { |
| 71 | + if (lastReportedOpenRef.current) { |
| 72 | + drawerRootContext.onNonDrawerDialogOpenChange(-1); |
| 73 | + lastReportedOpenRef.current = false; |
| 74 | + } |
| 75 | + }; |
| 76 | + }, [drawerRootContext, open]); |
| 77 | + |
56 | 78 | useOpenChangeComplete({ |
57 | 79 | open, |
58 | 80 | ref: store.context.popupRef, |
|
0 commit comments