Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Overlays & Windows

Modals, floating in-app windows, and popups are regular NanoUI actions controlled by a Var Bool that tracks whether they are open.

Always call overlays unconditionally

modal          :: Var Bool -> Text -> NanoUI () -> NanoUI ()
floatingWindow :: Var Bool -> Text -> NanoUI () -> NanoUI ()
popup          :: Var Bool -> PopupConfig -> NanoUI () -> NanoUI ()

Caution

Call every overlay on every frame, even when it is closed. Wrapping modal, floatingWindow, or popup inside when isShown shifts the widget IDs of every sibling after it whenever it opens or closes, breaking focus, carets, and per-row state. Closed overlays draw nothing.

confirmDelete = do
  showConfirm <- useVar False

  whenM (button "Delete File...") (writeVar showConfirm True)

  modal showConfirm "Confirm Deletion" $ do
    label "Are you sure you want to permanently delete this file?"
    row $ do
      whenM (button "Cancel") (writeVar showConfirm False)
      whenM (styled destructive (button "Delete")) $ do
        deleteFile
        writeVar showConfirm False

A modal draws above the page and blocks pointer and keyboard input behind it. Pressing Escape, clicking outside the dialog, or clicking its close button sets the Var Bool to False, closing the modal in the same frame.

Modals

modal draws a centered panel with a title bar and close button, clamped to fit inside the viewport. Its body does not scroll automatically: wrap long content in scrollWith, and give the modal an explicit size with modalWith when the body needs to fill it:

settingsDialog = do
  open <- useVar False
  modalWith (fixedWH 600 400) open "Settings" $
    columnWith (fillW . fillH) settingsBody

modal' returns (Response, Maybe a) and reports dismissal attempts through respClicked. When your open state is derived from another value (rather than stored directly in a Var Bool), pass constVar and update your real state from the response:

notice = do
  open <- useVar False
  isOpen <- readVar open
  (resp, _) <- modal' (constVar isOpen) "Important" $ do
    label "This dialog is shown while `open` is True."
    whenM (button "OK") (writeVar open False)
  when (respClicked resp) (writeVar open False)

If you want a modal backdrop and panel without a title bar or close button, use modalPanel or modalPanel'. Pressing Escape or clicking outside still closes it.

Floating windows

floatingWindow creates a draggable, resizable floating panel with a scrollable body. Unlike a modal, the main UI and any other open floating windows remain interactive around it:

inspector = do
  inspectorOpen <- useVar False
  floatingWindow inspectorOpen "Inspector" $ do
    inspectorBody

floatingWindow' returns both the body’s result and a Response. Use floatingWindow for inspectors, palettes, and tool panels that sit alongside the main view; use modal when the user needs to finish an interaction before returning to the page.

Popups

popup draws a floating panel positioned by a PopupConfig:

filterPopup = do
  filterOpen <- useVar False
  showFruit <- useVar True
  showVeg <- useVar True
  filterR <- button' "Filter"
  when (respClicked filterR) (modifyVar filterOpen not)

  popup filterOpen (defaultPopupConfig (AnchorRect (respRect filterR))) $ do
    checkbox "Fruit" showFruit
    checkbox "Vegetables" showVeg

Clicks on the anchor rectangle count as clicks inside the popup, so clicking the trigger button to dismiss a popup will not immediately pop it back open on the same press.

Key placement options:

  • AnchorRect (respRect r) anchors the popup to a widget; AnchorPoint pos anchors it to a specific coordinate.
  • popupPlacement chooses where the popup opens (PlacementAuto, PlacementBelow, PlacementAbove, PlacementAtCursor, and others).
  • popupOffset sets the pixel gap between the anchor and the popup.
  • popupDismissable = False prevents automatic closing on Escape or outside clicks so you can handle dismissal explicitly via popup'.

Because anchored popups read respRect (which comes from the previous frame), warm up one frame in headless tests before clicking to open them. For tall popup menus, cap the height with popupWith (maxH ...) and place a scroller inside.

Tooltips

Tooltips require no state Var and attach directly to any widget’s Response:

tooltips = do
  save <- button' "Save"
  tooltip save "Write the file to disk"

  more <- button' "More"
  tooltipConfigured defaultTooltipConfig
    {tooltipPlacement = PlacementAtCursor} more "Follows the pointer"

By default, tooltips appear after hovering for 0.5 seconds. Pass a TooltipConfig to tooltipConfigured to change the delay or placement, or use tooltipWidget, tooltipWidgetConfigured, or withTooltip to render a custom widget subtree inside the tooltip instead of plain text. Tooltips pass pointer events through to widgets underneath and keep their bodies inert so inner controls cannot steal keyboard focus.

Keep in mind

  • Modals stack in declaration order. Escape dismisses the innermost modal first; sibling modals close in declaration order.
  • Keep the open Var alive outside conditional branches. Allocate or read it in a scope that runs even while the overlay is hidden.
  • Check focus after overlay calls so focus queries see widgets declared inside open overlays.
  • Avoid nested borders. Putting a scrollArea, panel, or card inside a modal or popup draws a box inside a box; strip the inner chrome (see Double borders).

For a complete example connecting a menu bar of popup' panels and a close-confirmation modal, see Tutorial 2: Build a Notepad.