Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(lemon-ui): make modals scrollable on mobile Safari (#78305)

Ben Lead89bcde7a24d
diff --git a/frontend/src/lib/components/Cards/TextCard/TextCardModal.tsx b/frontend/src/lib/components/Cards/TextCard/TextCardModal.tsx
index 62421b2272f8..f0021a06dd6e 100644
--- a/frontend/src/lib/components/Cards/TextCard/TextCardModal.tsx
+++ b/frontend/src/lib/components/Cards/TextCard/TextCardModal.tsx
@@ -47,7 +47,7 @@ export function TextCardModal({
onOpenChange={(open) => !open && handleClose()}
disablePointerDismissal={hasUnsavedInput}
className={cn(
- 'w-[min(100vw-3rem,72rem)] min-w-full lg:min-w-6xl max-h-[calc(100vh-4rem)] top-8',
+ 'w-[min(100vw-3rem,72rem)] min-w-full lg:min-w-6xl max-h-[calc(100vh-4rem)] supports-[max-height:1dvh]:max-h-[calc(100dvh-4rem)] top-8',
'bg-surface-primary',
// DialogPrimitive defaults to z above --z-popover; rich editor toolbars portal to body at
// --z-popover and would sit under the panel. Sit the dialog just below that layer instead.
diff --git a/frontend/src/lib/components/Search/Search.tsx b/frontend/src/lib/components/Search/Search.tsx
index b2a90fd04333..b9035678ca1f 100644
--- a/frontend/src/lib/components/Search/Search.tsx
+++ b/frontend/src/lib/components/Search/Search.tsx
@@ -862,7 +862,7 @@ function SearchResults({
direction="vertical"
styledScrollbars
className={cn('flex-1 overflow-y-auto', className)}
- innerClassName="scroll-pt-12 scroll-pb-8"
+ innerClassName="scroll-pt-12 scroll-pb-8 overscroll-contain"
>
{!isAnyLoading && (
<Autocomplete.Empty className="px-3 py-8 text-center text-muted empty:p-0">
diff --git a/frontend/src/lib/lemon-ui/LemonModal/LemonModal.scss b/frontend/src/lib/lemon-ui/LemonModal/LemonModal.scss
index 372e39ae53ed..8d636800fb9b 100644
--- a/frontend/src/lib/lemon-ui/LemonModal/LemonModal.scss
+++ b/frontend/src/lib/lemon-ui/LemonModal/LemonModal.scss
@@ -1,3 +1,8 @@
+// Locks page scroll where the body is the scroller. No scrollbar-gutter: it would shift the app sideways.
+body.ReactModal__Body--open {
+ overflow: hidden;
+}
+
.LemonModal__overlay {
position: fixed;
inset: 0;
@@ -40,6 +45,9 @@
// Always give toasts some space at the bottom
max-height: calc(100vh - 60px - 2rem);
+
+ // dvh excludes the mobile browser toolbar; 100vh above is the fallback.
+ max-height: calc(100dvh - 60px - 2rem);
margin: 1rem auto;
background-color: var(--color-bg-surface-primary);
border: 1px solid var(--border-bold);
@@ -86,11 +94,15 @@
flex: 1;
flex-direction: column;
overflow-y: hidden;
+
+ // `simple` modals scroll here instead of in .LemonModal__content.
+ overscroll-behavior: contain;
}
.LemonModal__content {
padding: 1rem;
overflow-y: auto;
+ overscroll-behavior: contain;
&.LemonModal__content--embedded {
padding: 0;
diff --git a/frontend/src/lib/ui/DialogPrimitive/DialogPrimitive.tsx b/frontend/src/lib/ui/DialogPrimitive/DialogPrimitive.tsx
index d0917c56d0c1..4686424c09bc 100644
--- a/frontend/src/lib/ui/DialogPrimitive/DialogPrimitive.tsx
+++ b/frontend/src/lib/ui/DialogPrimitive/DialogPrimitive.tsx
@@ -18,12 +18,14 @@ function DialogPrimitive({
onOpenChange,
className,
disablePointerDismissal = false,
+ initialFocus,
}: {
children: React.ReactNode
open: boolean
onOpenChange: (open: boolean, eventDetails?: Dialog.Root.ChangeEventDetails) => void
className?: string
disablePointerDismissal?: boolean
+ initialFocus?: React.ComponentProps<typeof Dialog.Popup>['initialFocus']
}): JSX.Element {
return (
<Dialog.Root
@@ -35,8 +37,10 @@ function DialogPrimitive({
<Dialog.Portal>
<Dialog.Backdrop className="fixed inset-0 min-h-dvh min-w-dvw bg-black opacity-20 transition-all duration-150 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 dark:opacity-70 z-[var(--z-modal)]" />
<Dialog.Popup
+ initialFocus={initialFocus}
+ // dvh override is support-gated so browsers without dvh keep the vh cap.
className={cn(
- '@container fixed top-4 left-1/2 w-[400px] max-w-[calc(100vw-3rem)] max-h-[60vh] -translate-x-1/2 rounded-lg bg-surface-secondary shadow-xl border border-primary transition-all duration-150 data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 flex flex-col overflow-hidden z-[var(--z-force-modal-above-popovers)]',
+ '@container fixed top-4 left-1/2 w-[400px] max-w-[calc(100vw-3rem)] max-h-[60vh] supports-[max-height:1dvh]:max-h-[60dvh] -translate-x-1/2 rounded-lg bg-surface-secondary shadow-xl border border-primary transition-all duration-150 data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 flex flex-col overflow-hidden z-[var(--z-force-modal-above-popovers)]',
className
)}
>
diff --git a/frontend/src/scenes/dashboard/NewDashboardModal.tsx b/frontend/src/scenes/dashboard/NewDashboardModal.tsx
index 7239d6c183e7..6797ce92cc81 100644
--- a/frontend/src/scenes/dashboard/NewDashboardModal.tsx
+++ b/frontend/src/scenes/dashboard/NewDashboardModal.tsx
@@ -5,6 +5,7 @@ import { LemonButton, LemonInput } from '@posthog/lemon-ui'
import { DialogClose, DialogPrimitive, DialogPrimitiveTitle } from 'lib/ui/DialogPrimitive/DialogPrimitive'
import { cn } from 'lib/utils/css-classes'
+import { isMobile } from 'lib/utils/dom'
import { pluralize } from 'lib/utils/strings'
import { dashboardTemplateChooserLogic } from 'scenes/dashboard/dashboards/templates/dashboardTemplateChooserLogic'
import { dashboardTemplatesLogic } from 'scenes/dashboard/dashboards/templates/dashboardTemplatesLogic'
@@ -58,7 +59,8 @@ export function NewDashboardModal(): JSX.Element {
onChange={setTemplateFilter}
value={templateFilter}
fullWidth={true}
- autoFocus
+ // A focused input makes iOS pan the viewport on swipe instead of scrolling the list.
+ autoFocus={!isMobile()}
className="min-w-0 flex-1"
/>
<LemonButton
@@ -77,10 +79,12 @@ export function NewDashboardModal(): JSX.Element {
return (
<DialogPrimitive
+ // Base UI would otherwise focus the filter input on open.
+ initialFocus={!isMobile()}
open={newDashboardModalVisible}
onOpenChange={(open) => !open && hideNewDashboardModal()}
className={cn(
- 'w-[min(100vw-3rem,1200px)] max-h-[calc(100vh-4rem)] top-8',
+ 'w-[min(100vw-3rem,1200px)] max-h-[calc(100vh-4rem)] supports-[max-height:1dvh]:max-h-[calc(100dvh-4rem)] top-8',
'bg-surface-primary',
// Variable selectors in ActionFilter portal to the popover layer; keep this modal just below
// that layer so dropdown options render above the dialog instead of behind it.
diff --git a/products/workflows/frontend/Workflows/NewWorkflowModal.tsx b/products/workflows/frontend/Workflows/NewWorkflowModal.tsx
index 0a19ce8a393e..281549232f94 100644
--- a/products/workflows/frontend/Workflows/NewWorkflowModal.tsx
+++ b/products/workflows/frontend/Workflows/NewWorkflowModal.tsx
@@ -3,6 +3,7 @@ import { useActions, useValues } from 'kea'
import { LemonInput, LemonSelect } from '@posthog/lemon-ui'
import { LemonModal } from 'lib/lemon-ui/LemonModal'
+import { isMobile } from 'lib/utils/dom'
import { newWorkflowLogic } from './newWorkflowLogic'
import { WorkflowTemplateChooser } from './templates/WorkflowTemplateChooser'
@@ -37,7 +38,8 @@ export function NewWorkflowModal(): JSX.Element {
onChange={setTemplateFilter}
value={templateFilter}
fullWidth={true}
- autoFocus
+ // A focused input makes iOS pan the viewport on swipe instead of scrolling the list.
+ autoFocus={!isMobile()}
/>
{availableTags.length > 0 && (
<LemonSelect
diff --git a/products/workflows/frontend/Workflows/templates/WorkflowTemplateChooser.scss b/products/workflows/frontend/Workflows/templates/WorkflowTemplateChooser.scss
index 1209d8deda92..b77f2f36ab37 100644
--- a/products/workflows/frontend/Workflows/templates/WorkflowTemplateChooser.scss
+++ b/products/workflows/frontend/Workflows/templates/WorkflowTemplateChooser.scss
@@ -1,8 +1,8 @@
.WorkflowTemplateChooser {
display: grid;
- // Wide enough that a template description reads in two lines without being cut
- grid-template-columns: repeat(auto-fill, minmax(26rem, 1fr));
+ // Wide enough for a two-line description; min() lets it shrink on narrow screens.
+ grid-template-columns: repeat(auto-fill, minmax(min(26rem, 100%), 1fr));
gap: 0.5rem;
align-items: stretch;
}