11'use client'
22
3- import { type CSSProperties , useEffect , useRef , useState } from 'react'
3+ import { type CSSProperties , type RefObject , useEffect , useRef , useState } from 'react'
44import { chipBorderShadowRing , cn } from '@sim/emcn'
55import dynamic from 'next/dynamic'
66import { preconnect } from 'react-dom'
77import { DemoForm , type DemoLead } from '@/app/(landing)/demo/components/demo-form'
8+ import { applyLegacyInertFallback } from '@/app/(landing)/demo/components/legacy-inert-fallback'
89
910const importScheduler = ( ) => import ( '@/app/(landing)/demo/components/demo-scheduler' )
1011
@@ -32,6 +33,14 @@ const DemoScheduler = dynamic(() => importScheduler().then((m) => m.DemoSchedule
3233 loading : ( ) => null ,
3334} )
3435
36+ function useLegacyInertFallback ( ref : RefObject < HTMLDivElement | null > , inert : boolean ) {
37+ useEffect ( ( ) => {
38+ const node = ref . current
39+ if ( ! inert || ! node || 'inert' in HTMLElement . prototype ) return
40+ return applyLegacyInertFallback ( node )
41+ } , [ inert , ref ] )
42+ }
43+
3544interface DemoBookingProps {
3645 /** Layout/placement classes (grid cell). Never chrome. */
3746 className ?: string
@@ -59,8 +68,13 @@ export function DemoBooking({ className }: DemoBookingProps) {
5968 const [ lead , setLead ] = useState < DemoLead | null > ( null )
6069 const [ formHeight , setFormHeight ] = useState < number > ( )
6170 const formRef = useRef < HTMLDivElement > ( null )
71+ const formPanelRef = useRef < HTMLDivElement > ( null )
72+ const schedulerPanelRef = useRef < HTMLDivElement > ( null )
6273 const showScheduler = lead !== null
6374
75+ useLegacyInertFallback ( formPanelRef , showScheduler )
76+ useLegacyInertFallback ( schedulerPanelRef , ! showScheduler )
77+
6478 useEffect ( ( ) => {
6579 const node = formRef . current
6680 if ( ! node ) return
@@ -87,6 +101,7 @@ export function DemoBooking({ className }: DemoBookingProps) {
87101 style = { { transform : showScheduler ? 'translateX(-100%)' : undefined } }
88102 >
89103 < div
104+ ref = { formPanelRef }
90105 className = 'w-full min-w-0 shrink-0'
91106 inert = { showScheduler }
92107 onFocusCapture = { ( ) => void preloadScheduler ( ) }
@@ -95,7 +110,11 @@ export function DemoBooking({ className }: DemoBookingProps) {
95110 < DemoForm onComplete = { setLead } />
96111 </ div >
97112 </ div >
98- < div className = 'h-full w-full min-w-0 shrink-0' inert = { ! showScheduler } >
113+ < div
114+ ref = { schedulerPanelRef }
115+ className = 'h-full w-full min-w-0 shrink-0'
116+ inert = { ! showScheduler }
117+ >
99118 { lead ? < DemoScheduler lead = { lead } /> : null }
100119 </ div >
101120 </ div >
0 commit comments