shadcn/ui Combobox not scrolling inside a Dialog
Fix a shadcn/ui Combobox or Popover inside a Dialog: set modal={true} on Popover, stop wheel propagation on CommandList, and fix focus trapping.
- shadcn 4.23.0
- Tailwind CSS 4.3.5
- Vite 8
- React 19.3
Put a shadcn/ui Combobox (built from Popover + Command) inside a Dialog or Sheet and two things break: the mouse wheel refuses to scroll the option list, and clicking an option either fails or closes the parent dialog. Both happen because Radix Dialog locks body scroll and traps focus while Popover defaults to non-modal.
The two-line fix
Step 1: Set modal={true} on Popover
By default
<Popover>is non-modal, so the parentDialog'sreact-remove-scrolllayer intercepts wheel and touch events over the portal. Settingmodal={true}lets the popover own scroll and pointer events while it is open:combobox-in-dialog.tsxTSX <Popover open={open} onOpenChange={setOpen} modal={true}> <PopoverTrigger asChild> <Button variant="outline" role="combobox">Select country...</Button> </PopoverTrigger> <PopoverContent className="w-[--radix-popover-trigger-width] p-0"> <Command> <CommandInput placeholder="Search..." /> <CommandList className="max-h-60 overflow-y-auto"> <CommandEmpty>No match.</CommandEmpty> <CommandGroup>{/* items */}</CommandGroup> </CommandList> </Command> </PopoverContent></Popover>Step 2: Stop wheel propagation if scroll still locks on macOS
If your
DialogContentitself hasoverflow-y-auto, some browsers still swallow trackpad events on the inner list. AddonWheel={(e) => e.stopPropagation()}andonTouchMove={(e) => e.stopPropagation()}toCommandList:command-list.tsxTSX <CommandList className="max-h-60 overflow-y-auto" onWheel={(e) => e.stopPropagation()} onTouchMove={(e) => e.stopPropagation()}>
Two other causes inside Dialogs
- Popover opens behind the Dialog: Check the z-index in
components/ui/popover.tsxanddialog.tsx. Both default toz-50; because the popover portal mounts after the dialog, it usually stacks on top, unless a custom wrapper gives the dialogz-[60]. - Typing in CommandInput loses focus: Make sure the
PopoverContentis rendered inside theDialogtree (not hoisted outside by a custom portal container) so Radix's focus scope recognizes the input as part of the active dialog.
Questions
Does Base UI have the same Combobox-in-Dialog problem?
Less often: Base UI ships a first-class Combobox primitive that coordinates with its own Dialog portal. See shadcn/ui Base UI vs Radix for the trade-offs.
Why does Escape close both the Popover and the Dialog?
Without modal={true} on the Popover, both layers can receive the Escape keydown. With modal={true}, the first Escape closes only the Popover and the second closes the Dialog.
Related articles
- shadcn/uishadcn/ui Base UI vs Radix: which primitive library to pickCompare Radix UI (asChild, data-state) and Base UI (render prop, data-open) in shadcn/ui: composition, Tailwind v4 animations, registries, and when to pick each.
- shadcn/uishadcn/ui Button asChild not working: Slot errors and fixesFix React.Children.only and missing styles with shadcn/ui Button asChild: single child rule, fragments, forwarding props, and Base UI render prop.
- shadcn/uishadcn/ui animations not working on Tailwind v4Dialogs and accordions without animation mean a missing tw-animate-css or shadcn/tailwind.css import. Why the second one fails silently, and how to check.
Still stuck? We answer every message ourselves. Write to us