Skip to main content
Copy for LLM

Building Panels When They Are Needed

An overlay draws its panel in a <template> that Alpine moves to the end of the page as it starts, so every panel on a page starts with the page, whether its overlay ever opens or not. A page with a menu in every row, a tooltip on every icon or a confirmation for every record starts panels nobody looks at.

With lazy, an overlay keeps its panel in a <template> the browser does not render, and builds it the first time it is needed. Once built, the panel stays when the overlay closes again, and it opens, takes the focus and closes as a panel built with the page does. lazy is off by default.

The Overlays That Take It

Overlay Where lazy goes Built when Configuration key
Popover <x-wirekit::popover> the pointer or the focus reaches the trigger, or the popover opens components.popover.lazy
Dropdown <x-wirekit::dropdown>, in both forms the pointer or the focus reaches the trigger, or the menu opens components.dropdown.lazy
Notification center <x-wirekit::notification-center> the pointer or the focus reaches the bell, or the panel opens components.notification-center.lazy
Tooltip <x-wirekit::tooltip> the tooltip first shows components.tooltip.lazy
Text with truncate="tooltip" the configuration only the tooltip first shows on a cut text components.tooltip.lazy
Combobox <x-wirekit::combobox> the pointer or the focus reaches the field, or the list opens components.combobox.lazy
Multi-select <x-wirekit::multi-select>, in its dropdown layout the pointer or the focus reaches the field, or the list opens components.multi-select.lazy
Color picker <x-wirekit::color-picker>, in its popover mode the pointer or the focus reaches the picker, or the panel opens components.color-picker.lazy
Context menu <x-wirekit::context-menu> the menu first opens components.context-menu.lazy
Menubar <x-wirekit::menubar>, for each of its menus a menu first opens components.menubar.lazy
Navigation menu <x-wirekit::navigation-menu>, for each of its panels a panel first opens components.navigation-menu.lazy
Hover card <x-wirekit::hover-card> the card first shows components.hover-card.lazy
Modal <x-wirekit::modal> the modal first opens components.modal.lazy
Drawer <x-wirekit::drawer> the drawer first opens components.drawer.lazy
Alert dialog <x-wirekit::alert-dialog> the dialog first opens components.alert-dialog.lazy
Command palette <x-wirekit::command-palette> the palette first opens components.command-palette.lazy
Tour <x-wirekit::tour> the tour first starts components.tour.lazy
Lightbox <x-wirekit::lightbox> the viewer first opens components.lightbox.lazy
Filter builder <x-wirekit::filter-builder> the panel first opens, to add a filter or to edit one components.filter-builder.lazy
Date picker <x-wirekit::date-picker>, in popover mode the dialog first opens components.date-picker.lazy
Time picker <x-wirekit::time-picker>, in popover mode with a list of times the dialog first opens components.time-picker.lazy
Datetime picker <x-wirekit::datetime-picker> the dialog first opens components.datetime-picker.lazy

A select keeps its options in a template the same way, with lazy, until the field is first used.

Setting It for the Whole Application

Each overlay takes its default from its key under components in config/wirekit.php:

// config/wirekit.php
'components' => [
    'popover' => ['lazy' => true],
    'dropdown' => ['lazy' => true],
    'tooltip' => ['lazy' => true],
],

The prop on one overlay wins over the configuration: :lazy="false" builds that overlay's panel with the page.

What a Lazy Panel Changes

  • Until an overlay is built, its panel is not part of the page. A script that looks for something inside it, a browser test that reads it before the overlay opens, and a crawler that follows its links find nothing there. Open the overlay first, or leave lazy off for an overlay whose panel something has to find while it is closed.
  • A trigger that names its panel with aria-controls names it from the moment the panel is built, and names no element before.
  • A tooltip describes its trigger from the start all the same: its words stand hidden beside the trigger.
  • Inside a Livewire component, a render keeps a panel the overlay has built and updates it like any other part of the page, and an overlay that waits takes the new content for the moment it builds.
  • lazy on one overlay reaches no overlay inside it: a dropdown in a lazy popover builds its own panel as its own lazy says.

Was this page helpful?

Thank you for your feedback!

Voting requires cookies or local storage. What we store