Latitude ComponentsLibrary 0.1.0

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.

Version0.1.0
File/components/lat-modal/0.1.0/lat-modal.js (1.9 KB gzipped)
SHA-256cd75596f0b661c13a991421182135c868d4c26c3f221429e760fd17072ff77d7

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

Dark
Delete video This removes the video and all of its responses. You can’t undo this.
Light
Delete video This removes the video and all of its responses. You can’t undo this.
<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

Dark
Publish study Viewers can respond as soon as it’s published. You can still edit the questions until the first response comes in.
Light
Publish study Viewers can respond as soon as it’s published. You can still edit the questions until the first response comes in.
<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

Dark
Archive project

Archived projects are hidden from your team. Check that you’ve exported what you need.

Light
Archive project

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

AttributeValuesNotes
headingtextThe title, and the dialog's accessible name.
openbooleanShows it as a modal. Removed when it closes.
intentdefault, dangerDanger makes Confirm the Danger Primary button, for destructive confirmations.
confirm-labeltextDefault "Confirm". Use a verb: Delete, Publish, Archive.
cancel-labeltextDefault "Cancel".
confirm-disabledbooleanUntil required input is complete.

Slots, methods and events

NameKindNotes
(default)slotThe body: a sentence or a short form.
footerslotReplaces Cancel and Confirm. Keep the order: Secondary, then Primary, on the right.
show()methodOpens it.
close(action)methodCloses it; action defaults to dismiss.
returnValuepropertyThe action that last closed it.
closeeventdetail.action is confirm, cancel or dismiss (close button, Escape or close()). Doesn't bubble.