Use it inside a dialog
Where popups go (popupContainer) and Escape when you put the grid in a modal or popover
You can put the grid in a modal (the Modal / Dialog of shadcn/ui, Radix, Headless UI, HeroUI, Mantine or UI SDK, or a plain <dialog>) or a popover. The column menu, column filters, context menu, select editor options, tool panel, fill handle menu, tooltips and drag ghosts appear inside the dialog around the grid (since 1.1.0).
Demo (a dialog to choose a customer)
- "Open in a dialog" opens a plain
<dialog>withshowModal(). The column menu from the header's ⋮, the options from double-clicking "Region", and the context menu appear inside the dialog and can be pressed. - With
popupContainer="body", popups go directly underdocument.bodyand are hidden behind the dialog (top layer) (the behavior up to 1.0.2).
Where popups go (popupContainer)
| Value | Where they are drawn |
|---|---|
'auto' (default) | Inside the nearest dialog around the grid (<dialog> / an element with the popover attribute / aria-modal="true" / role="dialog" / role="alertdialog"). Without one, a grid inside a Shadow root uses the element wrapping the grid directly under that Shadow root (since 1.3.0; Grids inside Shadow DOM); otherwise directly under document.body. When the dialog is a fixed containing block that clips its content (the content of Mantine's Modal), inside the outer position: fixed ancestor ("Things to watch" below) |
'body' | Always directly under document.body (the same as up to 1.0) |
| An element | Inside that element |
| A function | Receives the grid's element and returns where to draw (null / undefined means document.body). Called on each render while a popup is open; not called while closed |
Directly under document.body, popups may not work inside a modal. A plain <dialog>'s showModal() and popover go to the top layer, so elements directly under body are hidden behind them. Modals of Radix (shadcn/ui), React Aria (HeroUI) and Headless UI block pointers outside (pointer-events: none on body), trap focus inside and close on outside presses, so popups directly under body can't be pressed or typed into. Radix's Dialog and Popover don't set aria-modal, so they're found by role="dialog".
// shadcn/ui's Dialog: without writing anything, popups appear inside DialogContent
<Dialog>
<DialogContent>
<SpreadsheetGrid rows={rows} columns={columns} />
</DialogContent>
</Dialog>
// Decide where to draw yourself
<SpreadsheetGrid rows={rows} columns={columns} popupContainer={(grid) => grid.closest<HTMLElement>('.sheet-frame')} />The place is decided every time a popup opens. Even if the <dialog> holding the grid is opened later with showModal(), popups appear inside it. Popups are added as the dialog's last child and removed when closed.
Things to watch
- Cancelling offsets: when an ancestor of the place has
transform/translateand the like (shadcn/ui's DialogContent is centered withtranslate), that element becomes the containing block forposition: fixed. The grid measures the offset and cancels it with the popup'stranslate(when opened and every time its position is recomputed). Scaling (scale) isn't cancelled. - Clipped by the dialog's frame: when that element clips its content with
overflowand also becomes the containing block forposition: fixedthroughtransformand the like (a dialog withmax-height,overflow-y: autoandtransform), popups are clipped by the dialog's frame too.'auto'uses an outerposition: fixedancestor if there is one (Mantine's Modal goes to.mantine-Modal-inneroutside the content, so nothing is clipped). Without one (a DialogContent that is itselfposition: fixedwithoverflow-y: auto, for example), popups are clipped, so pass a place that doesn't clip as an element or function ('body'is fine too if the dialog doesn't block pointers and focus outside it). - Tokens: CSS tokens (
--ssg-*) set on the table are copied to popups when they open, as before. Put thedarkclass oftheme="class"on<html>or<body>. - Popups you draw yourself: popups your code draws inside a custom editor or
renderCell(a list of options, for example) aren't covered bypopupContainer. Portaling them todocument.bodyhides them behind a modal<dialog>, where they can't be pressed. Like the grid, draw them inside the dialog around them (createPortal(list, anchor.closest('dialog') ?? document.body); in Solid,<Portal mount={anchor.closest('dialog') ?? document.body}>, whereanchoris the editor's input or similar. For Radix and other modals, pass the same element to that library's Portalcontainer). - Escape: the
Escapethe grid uses (cancelling an edit, closing a menu and so on) doesn't close the dialog. Details are in "A grid in a dialog" in Keyboard and touch. - Closing drops the grid's records: many dialogs unmount their content when closed, so the grid's change tracking (
trackChanges) records, undo history and selection go too (row values stay inrows). In dialogs that may be closed before saving, use a setting that keeps the content mounted (Radix / UI SDKforceMount/keepMountedand the like), or save withgetChanges()before closing. When you use AI agent tools, how to keep AI away from the table while it's closed is in Let AI agents operate the table.
Accessibility
Keyboard-only use, what screen readers hear, high contrast and reduced motion, and what to take care of in your app
Troubleshooting
Common questions (the table doesn't show, edits don't stick, undo is lost, pasted values don't go in, menus can't be pressed inside dialogs or Shadow DOM, 500 on Next.js and more) and known limitations