Modal
A dialog for a focused task or decision that blocks the rest of the app: confirmations, short forms and decisions that need full attention. Keep it to one task. Rules: UX Elements & Rules → Modal (R-O4, R-A6).
Add it to a page
Load the pinned file once in your Latitude Site or web page, then use the tag.
<script type="module" src="https://web-components.sites.latd.com/components/lat-modal/0.1.0/lat-modal.js"></script>The file is an ES module. It loads Lit, the design-system tokens and the Roobert stylesheet from this catalog once per page, however many components you use.
| Version | 0.1.0 |
|---|---|
| File | /components/lat-modal/0.1.0/lat-modal.js (1.9 KB gzipped) |
| SHA-256 | cd75596f0b661c13a991421182135c868d4c26c3f221429e760fd17072ff77d7 |
The close, Cancel and Confirm buttons are bundled in. To put buttons of your own in the footer slot, load <lat-button> too.
Permutations
Select a button to open its modal. Escape, the close button and Cancel all close it, and focus goes back to the button.
Danger confirmation
<lat-button intent="danger" onclick="this.nextElementSibling.show()">Delete video</lat-button>
<lat-modal heading="Delete video?" intent="danger" confirm-label="Delete">
This removes the video and all of its responses. You can’t undo this.
</lat-modal>Default confirmation, with the close event
<lat-button variant="primary" onclick="this.nextElementSibling.show()">Publish study</lat-button>
<lat-modal heading="Publish study?" confirm-label="Publish"
onclose="this.nextElementSibling.value = 'Closed with ' + event.detail.action">
Viewers can respond as soon as it’s published. You can still edit the questions until the first response comes in.
</lat-modal>
<output></output>Confirm disabled until input is complete
Archived projects are hidden from your team. Check that you’ve exported what you need.
Archived projects are hidden from your team. Check that you’ve exported what you need.
<lat-button onclick="this.nextElementSibling.show()">Archive project</lat-button>
<lat-modal heading="Archive project?" confirm-label="Archive" confirm-disabled>
<p>Archived projects are hidden from your team. Check that you’ve exported what you need.</p>
<label style="display: flex; gap: 8px; margin-top: 16px">
<input type="checkbox" onchange="this.closest('lat-modal').confirmDisabled = !this.checked" />
I’ve exported the results
</label>
</lat-modal>Opening it from script
const modal = document.querySelector("lat-modal");
modal.show(); // or modal.open = true
modal.addEventListener("close", (event) => {
if (event.detail.action === "confirm") deleteVideo();
});Attributes
| Attribute | Values | Notes |
|---|---|---|
heading | text | The title, and the dialog's accessible name. |
open | boolean | Shows it as a modal. Removed when it closes. |
intent | default, danger | Danger makes Confirm the Danger Primary button, for destructive confirmations. |
confirm-label | text | Default "Confirm". Use a verb: Delete, Publish, Archive. |
cancel-label | text | Default "Cancel". |
confirm-disabled | boolean | Until required input is complete. |
Slots, methods and events
| Name | Kind | Notes |
|---|---|---|
| (default) | slot | The body: a sentence or a short form. |
footer | slot | Replaces Cancel and Confirm. Keep the order: Secondary, then Primary, on the right. |
show() | method | Opens it. |
close(action) | method | Closes it; action defaults to dismiss. |
returnValue | property | The action that last closed it. |
close | event | detail.action is confirm, cancel or dismiss (close button, Escape or close()). Doesn't bubble. |