Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions src/components/clinical-dashboard/global-mockup-search-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ function GlobalMockupSearchShellClient({
useEffect(() => {
reportPhoneScrollHideRef.current = phoneScrollHide.reportScroll;
}, [phoneScrollHide.reportScroll]);
const scrollCaptureCleanupRef = useRef<(() => void) | null>(null);
const visibleShellModes = useMemo(() => {
const modes = visibleAppModeDefinitions();
if (!availableModeIds?.length) return modes;
Expand Down Expand Up @@ -322,19 +321,15 @@ function GlobalMockupSearchShellClient({
phoneScrollHide.reportScroll(event.currentTarget.scrollTop);
}

const isMedicationDetailRoute = /^\/medications\/[^/]+$/.test(pathname);
const shouldRenderClinicalDashboard = !isMedicationDetailRoute && (isHomeRoute || shouldRenderDashboardSearch);

// Page canvases can become nested scrollers when `overflow-x-hidden` pairs with
// a flex height cap (overflow-y becomes auto per CSS). Capture descendant scroll
// so the phone dock/header still hide while users scroll results.
const setMainRef = (main: HTMLDivElement | null) => {
mainRef.current = main;

// Clean up any previous listener before attaching a new one.
if (scrollCaptureCleanupRef.current) {
scrollCaptureCleanupRef.current();
scrollCaptureCleanupRef.current = null;
}

if (!main) return;
useEffect(() => {
const main = mainRef.current;
if (!main) return undefined;

const onScrollCapture = (event: Event) => {
const target = event.target;
Expand All @@ -344,11 +339,8 @@ function GlobalMockupSearchShellClient({
};

main.addEventListener("scroll", onScrollCapture, { capture: true, passive: true });
scrollCaptureCleanupRef.current = () => main.removeEventListener("scroll", onScrollCapture, { capture: true });
};

const isMedicationDetailRoute = /^\/medications\/[^/]+$/.test(pathname);
const shouldRenderClinicalDashboard = !isMedicationDetailRoute && (isHomeRoute || shouldRenderDashboardSearch);
return () => main.removeEventListener("scroll", onScrollCapture, { capture: true });
}, [shouldRenderClinicalDashboard, chromeVisible]);

if (shouldRenderClinicalDashboard) {
return (
Expand All @@ -364,7 +356,7 @@ function GlobalMockupSearchShellClient({
if (!chromeVisible) {
return (
<div className="min-h-dvh bg-[color:var(--background)] text-[color:var(--text)]">
<div id="main-content" ref={setMainRef} tabIndex={-1} className="min-h-dvh min-w-0 overflow-x-hidden focus:outline-none">
<div id="main-content" tabIndex={-1} className="min-h-dvh min-w-0 overflow-x-hidden focus:outline-none">
{children}
</div>
</div>
Expand Down Expand Up @@ -473,7 +465,7 @@ function GlobalMockupSearchShellClient({

<div
id="main-content"
ref={setMainRef}
ref={mainRef}
tabIndex={-1}
onScroll={handleMainScroll}
className={cn(
Expand Down