Dialogs and overlays
Show a dialog, a bottom sheet, a menu or a toast above the rest of your app. Start with a ready-made UI component, and build your own with <overlay> or LynxPortal when none fits.
Use a UI component
Add a component with npx @blotch/dolan add dialog. It copies the source into src/components/ui/, so you can change it.
They handle the backdrop, animation and touch rules below for you.
Build one with <overlay>
<overlay>floats above the whole app. It lives in your template, and a signal bound tovisibleshows and hides it.- Give it exactly one child, sized
h-full w-full. The overlay itself takes no space. It sizes only its first child, against the screen, and the web preview shows only that first child. Position your content inside that full-size view. - Use
(catchtap)on the panel. It stops taps on the panel from reaching the backdrop's close handler. See Stop an event from bubbling. - On Android, the back button fires
(bindrequestclose)on the overlay. Close the overlay there.
Open an overlay from code
Use LynxPortal when the code that opens the overlay isn't the template that shows it, such as a service, a route guard or a shared confirm step. It renders a component or a template inside a new <overlay>.
An overlay opened with LynxPortal stays open when the component that opened it is destroyed. Keep the PortalRef it returns, and call destroy() when you're done and when the opener is destroyed.
- Defer
open()anddestroy()withsetTimeoutinside a handler. Both create or destroy views. See thesetTimeoutrule. - The opened component is a normal component. It can inject services and use inputs, outputs and signals.
ref.instanceis the component, andref.setInput()changes an input later. inputssets inputs when it opens.injectorgives it a different injector. SeeLynxPortal.
Open a template
openTemplate() takes a TemplateRef from viewChild(), and an optional context for the template's variables.
Stack overlays with level
level picks one of four layers for an overlay. Set it on the element, <overlay [level]="2">, or when opening, portal.open(ConfirmDialog, { level: 2 }).
- Level 1, the default, is the top layer. Level 4 is the lowest, so a higher number sits further back.
- Within one level, the overlay shown last is on top.
- Pick the level before the overlay shows. Lynx doesn't move an overlay that's already visible to a new level.
Limitations
- An overlay blocks the whole app while it's visible. It takes every touch, even when its content is small. For a toast or banner, use the Toast component, which floats a
position: fixedview instead. - The host app must include Lynx's XElement library, which provides
<overlay>. Lynx Explorer and the apps thatng build --platformmakes include it. If you embed your bundle in your own app, register it there.
Related
<overlay>: every attribute and eventLynxPortal:PortalRefandPortalConfig- Accessibility: keep screen reader focus inside a dialog
- Modal dialog example
