UI.Modal
luastra/uiUI.Modal(input: Input): Node
Creates an accessible dialog above the current screen, moves focus to an optional declared child, relates visible descriptive text, traps navigation, and restores the originating focus after dismissal.
Mental model
This is a declarative node: app.render describes it again from current state, while the host matches its stable id to the existing view.
Before you use it
Add luastra/ui to this module's dependencies in luastra.json, then import it with require("luastra/ui"). The project must declare the ui.render capability. app.render must return one UI.Screen root; place this node inside that tree rather than invoking it for a hidden side effect.
How it fits
The constructor validates its fields immediately and returns a UI.Node. After app.render returns, the host reconciles that node by stable id with the current semantic DOM-based interface. Current desktop and mobile hosts package the same web artifact; native adapters are used at capability boundaries.
When to use it
Use UI.Modal for short blocking decisions or focused information that must be handled before returning to the page. Declare initialFocus and descriptionId when the default focus order or label needs explicit relationships.
Shared parameter groups
Parameters
| Parameter | Type / values | Description |
|---|---|---|
| id | lowercase path, required | Unique dialog ID. |
| open | boolean, required | Shows or hides the modal. |
| label | string, required | Accessible dialog name. |
| initialFocus | component ID? | Optional focusable descendant to focus after insertion. |
| descriptionId | component ID? | Optional visible descriptive descendant. |
| children | UI.Node[] | Heading, content, and close action. |
| padding | none | xs | sm | md | lg | xl | responsive | All-side inner spacing; responsive is supported only by padding. Group: Layout and surfaces. |
| margin | none | xs | sm | md | lg | xl | All-side outer spacing. Group: Layout and surfaces. |
| paddingX / paddingY | none | xs | sm | md | lg | xl | Axis-specific inner spacing. Group: Layout and surfaces. |
| paddingTop / paddingBottom / paddingStart / paddingEnd | none | xs | sm | md | lg | xl | Logical side-specific inner spacing. Group: Layout and surfaces. |
| marginX / marginY | none | xs | sm | md | lg | xl | Axis-specific outer spacing. Group: Layout and surfaces. |
| marginTop / marginBottom / marginStart / marginEnd | none | xs | sm | md | lg | xl | Logical side-specific outer spacing. Group: Layout and surfaces. |
| surface | plain | card | elevated | accent | Background, border, and elevation. Group: Layout and surfaces. |
| width | full | content | wide | Available width, 720 px maximum, or 1180 px maximum. Group: Layout and surfaces. |
| className | safe string ≤ 256 bytes | Additional admitted class tokens. Group: Layout and surfaces. |
| hidden | boolean | Visibility state. Group: State and semantics. |
| busy | boolean | aria-busy state. Group: State and semantics. |
| textColor | token | #RRGGBB | Local or inherited foreground. Group: Text and local colors. |
| backgroundColor | token | #RRGGBB | Component-box background. Group: Text and local colors. |
| Color tokens | accent | danger | muted | surface | success | text | transparent | warning | Current Screen theme colors. Group: Text and local colors. |
| onDismiss | action string | Modal dismissal action. Group: Events and motion. |
| motion | { [property]: Tween | Sequence } | Opacity, rotation, scale, and translation channels. Group: Events and motion. |
Children and layout
Heading, content, and close action.
Accessibility and keyboard
The host traps focus inside the open dialog, Escape invokes onDismiss, and closing restores focus to the trigger.
Common mistakes
- Removing the close button and relying only on Escape.
- Rendering interactive content outside and above an open modal.
Returns
Node — a validated declarative UI node that becomes part of the next host-neutral render tree.
What happens next
A validated declarative node appears after it is returned as part of the current render tree.
Failures and fixes
Invalid fields, duplicate IDs, unsupported child combinations, or a missing ui.render capability fail during check, render-tree validation, or host startup.
Availability
Source API in 0.5.0-alpha; the public installer targets 0.5.0-alpha. Verify host-specific behavior against the selected SDK.
Focused example
UI.Modal {
id = "help/modal",
open = helpOpen,
label = "Help",
onDismiss = "help.close",
UI.Text { id = "help/title", text = "Help", variant = "heading" },
UI.Button { id = "help/close", text = "Close", onTap = "help.close" },
}Continue with a complete recipe
This checked recipe uses UI.Modal inside complete authored files with the required manifest, test, and run steps.
Open validate a form and confirm in a modal recipe