Feedback and overlays
Dialog
A modal window around a native <dialog class="kui-dialog">. The browser keeps focus inside and makes the page behind it inert. <kui-dialog> adds opening from a button, closing on a press outside, focus back to the button, and the scroll lock. kui.confirm() asks a yes-or-no question in one call.
Examples
A dialog with a form
A button with data-kui-open="ID" opens the dialog with that id. Any button with data-kui-close="VALUE" closes it, and the kui-close event carries the value. The field with autofocus gets focus when it opens.
<button class="kui-button kui-button--primary" type="button" data-kui-open="dialog-rename"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#pencil"></use></svg><span>Rename project</span></button>
<kui-dialog id="dialog-rename">
<dialog class="kui-dialog" aria-labelledby="dialog-rename-title">
<div class="kui-dialog__head">
<h2 class="kui-dialog__title" id="dialog-rename-title">Rename project</h2>
<button class="kui-button kui-button--icon kui-button--ghost kui-dialog__close" data-kui-close><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button>
</div>
<div class="kui-dialog__body">
<div class="kui-field">
<label class="kui-label" for="dialog-rename-name">Name</label>
<input class="kui-input" id="dialog-rename-name" value="Godišnji izveštaj 2026" autofocus aria-describedby="dialog-rename-hint">
<p class="kui-hint" id="dialog-rename-hint">Everyone in the team sees the new name at once.</p>
</div>
</div>
<div class="kui-dialog__foot">
<button class="kui-button" data-kui-close="cancel">Cancel</button>
<button class="kui-button kui-button--primary" data-kui-close="save">Save name</button>
</div>
</dialog>
</kui-dialog>
Confirm, and confirm a destructive action
kui.confirm({ title, message, confirm, cancel, danger }) resolves to true when the person confirms. With danger the confirm button is red and Cancel has the first focus, so Enter does nothing harmful. Both are static: a press outside does not close them.
<button class="kui-button" type="button" data-example-confirm data-title="Send 14 invoices?" data-message="They go out by email to 14 clients now. You can still cancel each one for an hour." data-confirm="Send invoices" data-result="dialog-confirm-out" data-yes="Sent. 14 invoices are on their way.">Send invoices</button>
<button class="kui-button kui-button--danger" type="button" data-example-confirm data-danger data-title="Delete the project “Godišnji izveštaj 2026”?" data-message="Its 38 documents and every comment on them are deleted for the whole team. This cannot be undone." data-confirm="Delete project" data-result="dialog-confirm-out" data-yes="The project was deleted."><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#trash"></use></svg><span>Delete project</span></button>
<p class="kui-text-sm kui-text-muted" id="dialog-confirm-out" role="status"></p>
The call
const yes = await kui.confirm({
title: 'Delete the project “Godišnji izveštaj 2026”?',
message: 'Its 38 documents are deleted for the whole team. This cannot be undone.',
confirm: 'Delete project', // defaults to the keyed OK
danger: true,
});
if (yes) await deleteProject();
document.getElementById('dialog-rename').addEventListener('kui-close', (e) => {
if (e.detail.value === 'save') save(); // '' after Escape or a press outside
});<div class="kui-codeblock"><pre tabindex="0" aria-label="Script that asks for confirmation"><code>const yes = await kui.confirm({
title: 'Delete the project “Godišnji izveštaj 2026”?',
message: 'Its 38 documents are deleted for the whole team. This cannot be undone.',
confirm: 'Delete project', // defaults to the keyed OK
danger: true,
});
if (yes) await deleteProject();
document.getElementById('dialog-rename').addEventListener('kui-close', (e) => {
if (e.detail.value === 'save') save(); // '' after Escape or a press outside
});</code></pre></div>
Sizes and a long body
--sm for a question, the default for a short form, --lg for a longer one. When the body is taller than the screen it scrolls on its own and the head and the buttons stay.
<button class="kui-button" type="button" data-kui-open="dialog-terms">Read the terms</button>
<kui-dialog id="dialog-terms">
<dialog class="kui-dialog kui-dialog--lg" aria-labelledby="dialog-terms-title">
<div class="kui-dialog__head">
<h2 class="kui-dialog__title" id="dialog-terms-title">Terms of the data processing agreement</h2>
<button class="kui-button kui-button--icon kui-button--ghost kui-dialog__close" data-kui-close><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button>
</div>
<div class="kui-dialog__body" tabindex="0" role="region" aria-label="Terms">
<p>1. The processor handles personal data only on documented instructions from the controller, including transfers to a third country.</p>
<p>2. Persons authorised to process the data have committed themselves to confidentiality.</p>
<p>3. The processor takes every measure required under Article 32: encryption at rest and in transit, separation of customers, and tested backups.</p>
<p>4. The processor does not engage another processor without prior specific or general written authorisation of the controller.</p>
<p>5. Taking into account the nature of the processing, the processor assists the controller by appropriate measures in answering requests of data subjects.</p>
<p>6. At the choice of the controller, the processor deletes or returns all personal data after the end of the provision of services.</p>
<p>7. Obrađivač stavlja na raspolaganje rukovaocu sve informacije potrebne za dokazivanje ispunjenosti obaveza iz ovog člana.</p>
<p>8. Der Auftragsverarbeiter unterstützt den Verantwortlichen bei der Datenschutz-Folgenabschätzung.</p>
</div>
<div class="kui-dialog__foot">
<button class="kui-button" data-kui-close="later">Later</button>
<button class="kui-button kui-button--primary" data-kui-close="accept">Accept terms</button>
</div>
</dialog>
</kui-dialog>
<button class="kui-button" type="button" data-kui-open="dialog-static">Static dialog</button>
<kui-dialog id="dialog-static" static>
<dialog class="kui-dialog kui-dialog--sm" aria-labelledby="dialog-static-title" aria-describedby="dialog-static-text">
<div class="kui-dialog__head"><h2 class="kui-dialog__title" id="dialog-static-title">Choose a workspace</h2></div>
<div class="kui-dialog__body"><p id="dialog-static-text">A press outside does not close this dialog, because the page behind it needs a choice. Escape still closes it.</p></div>
<div class="kui-dialog__foot">
<button class="kui-button" data-kui-close="personal">Personal</button>
<button class="kui-button kui-button--primary" data-kui-close="company">Inzynk d.o.o.</button>
</div>
</dialog>
</kui-dialog>
States
Every state
Opening fades the dialog in and blurs the page behind it; with reduced motion it appears at once. On a phone the buttons stack full width with the main one on top. A danger dialog has a red dot before its title and a red confirm button, so the colour never stands alone.
<button class="kui-button" type="button" data-example-confirm data-title="Leave without saving?" data-message="You changed 3 fields. They are lost when you leave." data-confirm="Leave" data-cancel="Keep editing" data-danger data-result="dialog-state-out" data-yes="You left the form." data-no="You are still editing.">Leave the form</button>
<p class="kui-text-sm kui-text-muted" id="dialog-state-out" role="status"></p>
Classes and attributes
<kui-dialog id>- Wraps one native dialog. Attribute static: a press outside does not close it.
data-kui-open="ID"- On any button: opens the dialog, drawer or palette with that id, and gives focus back to this button when it closes.
data-kui-close="VALUE"- On a button inside: closes the dialog with that value. An empty icon-only close button gets the keyed name “Close”.
.kui-dialog, --sm, --lg, --danger- The native dialog and its width. --danger marks a destructive question.
.kui-dialog__head, __title, __close, __body, __foot- The parts. The body scrolls; the head and the foot stay.
open(trigger), close(value), isOpen- Methods and a property of kui-dialog.
kui-open, kui-close- Events; kui-close has detail.value.
kui.confirm(options)- title, message, confirm, cancel, danger. Resolves to true or false. Uses role="alertdialog".
Keyboard
- Tab or Shift + Tab
- Moves between the controls of the dialog. Focus does not leave it.
- Escape
- Closes the dialog with the value "", also a static one.
- Enter
- Presses the focused button. In a danger confirm, Cancel has focus first.
Accessibility
- Follows the WAI-ARIA dialog (modal) pattern.
aria-labelledbypoints at the title; addaria-describedbywhen one paragraph explains the question. - Focus goes to the field with autofocus, else to the first control. On close it goes back to the button that opened the dialog.
- The page behind is inert: a screen reader cannot wander into it, and it does not scroll.
- A question that interrupts uses
role="alertdialog"; kui.confirm sets it. - The close button of the head is an extra; Escape and a Cancel button must also work.
Do and do not
Do
- Title the dialog with the question or the task: “Rename project”.
- Name the confirm button with the verb: “Delete project”, never “Yes”.
- Say in a destructive confirm what is lost and that it cannot be undone.
Do not
- Do not open a dialog from inside another dialog.
- Do not use a dialog for news; use a toast.
- Do not ask for confirmation of an action that has an Undo.