Anatomy
aegov-modal renders a fixed backdrop and a centred (or top/bottom-docked) dialog, both inside a real shadow root. The component stays where it's declared in markup and takes its z-index from a shared overlay manager; only while open, and only if an ancestor would trap it (a transform, filter, stacking context, or hidden ancestor), does it move out of that ancestor, returning on close.

| Item | Name | Description |
|---|---|---|
1 |
Backdrop | The dimmed overlay behind the dialog. Clicking it closes the modal by default. |
2 |
Dialog | The role="dialog" content panel — the default slot renders here. |
3 |
Slotted content | Your own heading, body text, and action buttons — there's no separate header/footer slot. |
Opening and closing
Control the modal imperatively with show()/close()/toggle() from a trigger's click handler, or declaratively by toggling is-open from your framework's own state. Both paths run the identical open/close sequence — the modal correctly opens even when is-open="true" is present from the very first render, not only on a later change.
Delete this application?
This will permanently remove your draft application for the Emirates ID renewal service. This action cannot be undone.
<aegov-button id="open-confirm">Delete application</aegov-button>
<aegov-modal id="confirm-modal" label="Delete this application?">
<h3 id="confirm-title" class="font-bold text-xl mb-2">Delete this application?</h3>
<p class="text-base mb-6">This will permanently remove your draft application for the Emirates ID renewal service. This action cannot be undone.</p>
<div class="flex justify-end gap-3">
<aegov-button variant="secondary" id="cancel-confirm">Cancel</aegov-button>
<aegov-button variant="danger" id="confirm-delete">Delete</aegov-button>
</div>
</aegov-modal>
<script>
const modal = document.getElementById('confirm-modal');
document.getElementById('open-confirm').addEventListener('click', () => modal.show());
document.getElementById('cancel-confirm').addEventListener('click', () => modal.close());
document.getElementById('confirm-delete').addEventListener('click', () => modal.close());
</script>
import { useRef } from 'react';
import { AegovButton, AegovModal } from '@aegov/designsystem-react';
export default function ModalConfirm() {
const modalRef = useRef<HTMLAegovModalElement>(null);
return (
<>
<AegovButton onClick={() => modalRef.current?.show()}>Delete application</AegovButton>
<AegovModal ref={modalRef} label="Delete this application?">
<h3 id="confirm-title" className="font-bold text-xl mb-2">Delete this application?</h3>
<p className="text-base mb-6">This will permanently remove your draft application for the Emirates ID renewal service. This action cannot be undone.</p>
<div className="flex justify-end gap-3">
<AegovButton variant="secondary" onClick={() => modalRef.current?.close()}>Cancel</AegovButton>
<AegovButton variant="danger" onClick={() => modalRef.current?.close()}>Delete</AegovButton>
</div>
</AegovModal>
</>
);
}
<template>
<aegov-button @click="modal?.show()">Delete application</aegov-button>
<aegov-modal ref="modal" label="Delete this application?">
<h3 id="confirm-title" class="font-bold text-xl mb-2">Delete this application?</h3>
<p class="text-base mb-6">This will permanently remove your draft application for the Emirates ID renewal service. This action cannot be undone.</p>
<div class="flex justify-end gap-3">
<aegov-button variant="secondary" @click="modal?.close()">Cancel</aegov-button>
<aegov-button variant="danger" @click="modal?.close()">Delete</aegov-button>
</div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modal = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovModal } from '@aegov/designsystem-angular';
@Component({
selector: 'app-modal-confirm',
imports: [AegovButton, AegovModal],
template: `
<aegov-button (click)="modal.show()">Delete application</aegov-button>
<aegov-modal #modal label="Delete this application?">
<h3 id="confirm-title" class="font-bold text-xl mb-2">Delete this application?</h3>
<p class="text-base mb-6">This will permanently remove your draft application for the Emirates ID renewal service. This action cannot be undone.</p>
<div class="flex justify-end gap-3">
<aegov-button variant="secondary" (click)="modal.close()">Cancel</aegov-button>
<aegov-button variant="danger" (click)="modal.close()">Delete</aegov-button>
</div>
</aegov-modal>
`,
})
export class ModalConfirmComponent {
@ViewChild('modal') modal!: ElementRef;
}
Sizes
size sets the panel's fixed width (300px, 600px, 800px or 1140px, capped at the viewport width) and scales padding and corner radius together, mirroring aegov-card's own size tokens. sm suits a short yes/no confirmation; base is the default; lg gives forms and richer content more room; xl fits data-heavy or multi-column layouts.
Compact dialog
Small size suits a short confirmation.
Standard dialog
Base size fits most confirmations and short forms.
Spacious dialog
Large size gives forms and richer content more room.
Extra large dialog
Extra large fits data-heavy or multi-column content.
<aegov-button id="size-sm">Small</aegov-button>
<aegov-button id="size-base">Base</aegov-button>
<aegov-button id="size-lg">Large</aegov-button>
<aegov-button id="size-xl">Extra large</aegov-button>
<aegov-modal id="modal-sm" size="sm" label="Small modal">
<h3 class="font-bold text-lg mb-2">Compact dialog</h3>
<p class="text-base mb-6">Small size suits a short confirmation.</p>
<div class="flex justify-end"><aegov-button id="close-sm" size="sm">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-base" size="base" label="Base modal">
<h3 class="font-bold text-xl mb-2">Standard dialog</h3>
<p class="text-base mb-6">Base size fits most confirmations and short forms.</p>
<div class="flex justify-end"><aegov-button id="close-base">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-lg" size="lg" label="Large modal">
<h3 class="font-bold text-2xl mb-2">Spacious dialog</h3>
<p class="text-base mb-6">Large size gives forms and richer content more room.</p>
<div class="flex justify-end"><aegov-button id="close-lg">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-xl" size="xl" label="Extra large modal">
<h3 class="font-bold text-2xl mb-2">Extra large dialog</h3>
<p class="text-base mb-6">Extra large fits data-heavy or multi-column content.</p>
<div class="flex justify-end"><aegov-button id="close-xl">Close</aegov-button></div>
</aegov-modal>
<script>
['sm','base','lg','xl'].forEach(s => {
const m = document.getElementById('modal-' + s);
document.getElementById('size-' + s).addEventListener('click', () => m.show());
document.getElementById('close-' + s).addEventListener('click', () => m.close());
});
</script>
import { useRef, type ComponentRef } from 'react';
import { AegovButton, AegovModal } from '@aegov/designsystem-react';
const sizes = [
{ key: 'sm', label: 'Small', heading: 'Compact dialog', headingClass: 'text-lg', body: 'Small size suits a short confirmation.' },
{ key: 'base', label: 'Base', heading: 'Standard dialog', headingClass: 'text-xl', body: 'Base size fits most confirmations and short forms.' },
{ key: 'lg', label: 'Large', heading: 'Spacious dialog', headingClass: 'text-2xl', body: 'Large size gives forms and richer content more room.' },
{ key: 'xl', label: 'Extra large', heading: 'Extra large dialog', headingClass: 'text-2xl', body: 'Extra large fits data-heavy or multi-column content.' },
] as const;
export default function ModalSizes() {
const modals = useRef<Record<string, ComponentRef<typeof AegovModal> | null>>({});
return (
<>
<div className="flex flex-wrap gap-3">
{sizes.map(s => (
<AegovButton key={s.key} onClick={() => modals.current[s.key]?.show()}>{s.label}</AegovButton>
))}
</div>
{sizes.map(s => (
<AegovModal key={s.key} ref={(el) => { modals.current[s.key] = el; }} size={s.key} label={`${s.label} modal`}>
<h3 className={`font-bold ${s.headingClass} mb-2`}>{s.heading}</h3>
<p className="text-base mb-6">{s.body}</p>
<div className="flex justify-end">
<AegovButton onClick={() => modals.current[s.key]?.close()}>Close</AegovButton>
</div>
</AegovModal>
))}
</>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button @click="modalSm?.show()">Small</aegov-button>
<aegov-button @click="modalBase?.show()">Base</aegov-button>
<aegov-button @click="modalLg?.show()">Large</aegov-button>
<aegov-button @click="modalXl?.show()">Extra large</aegov-button>
</div>
<aegov-modal ref="modalSm" size="sm" label="Small modal">
<h3 class="font-bold text-lg mb-2">Compact dialog</h3>
<p class="text-base mb-6">Small size suits a short confirmation.</p>
<div class="flex justify-end"><aegov-button size="sm" @click="modalSm?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalBase" size="base" label="Base modal">
<h3 class="font-bold text-xl mb-2">Standard dialog</h3>
<p class="text-base mb-6">Base size fits most confirmations and short forms.</p>
<div class="flex justify-end"><aegov-button @click="modalBase?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalLg" size="lg" label="Large modal">
<h3 class="font-bold text-2xl mb-2">Spacious dialog</h3>
<p class="text-base mb-6">Large size gives forms and richer content more room.</p>
<div class="flex justify-end"><aegov-button @click="modalLg?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalXl" size="xl" label="Extra large modal">
<h3 class="font-bold text-2xl mb-2">Extra large dialog</h3>
<p class="text-base mb-6">Extra large fits data-heavy or multi-column content.</p>
<div class="flex justify-end"><aegov-button @click="modalXl?.close()">Close</aegov-button></div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modalSm = ref(null);
const modalBase = ref(null);
const modalLg = ref(null);
const modalXl = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovModal } from '@aegov/designsystem-angular';
@Component({
selector: 'app-modal-sizes',
imports: [AegovButton, AegovModal],
template: `
<div class="flex flex-wrap gap-3">
<aegov-button (click)="sm.show()">Small</aegov-button>
<aegov-button (click)="base.show()">Base</aegov-button>
<aegov-button (click)="lg.show()">Large</aegov-button>
<aegov-button (click)="xl.show()">Extra large</aegov-button>
</div>
<aegov-modal #sm size="sm" label="Small modal">
<h3 class="font-bold text-lg mb-2">Compact dialog</h3>
<p class="text-base mb-6">Small size suits a short confirmation.</p>
<div class="flex justify-end"><aegov-button size="sm" (click)="sm.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #base size="base" label="Base modal">
<h3 class="font-bold text-xl mb-2">Standard dialog</h3>
<p class="text-base mb-6">Base size fits most confirmations and short forms.</p>
<div class="flex justify-end"><aegov-button (click)="base.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #lg size="lg" label="Large modal">
<h3 class="font-bold text-2xl mb-2">Spacious dialog</h3>
<p class="text-base mb-6">Large size gives forms and richer content more room.</p>
<div class="flex justify-end"><aegov-button (click)="lg.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #xl size="xl" label="Extra large modal">
<h3 class="font-bold text-2xl mb-2">Extra large dialog</h3>
<p class="text-base mb-6">Extra large fits data-heavy or multi-column content.</p>
<div class="flex justify-end"><aegov-button (click)="xl.close()">Close</aegov-button></div>
</aegov-modal>
`,
})
export class ModalSizesComponent {
@ViewChild('sm') sm!: ElementRef;
@ViewChild('base') base!: ElementRef;
@ViewChild('lg') lg!: ElementRef;
@ViewChild('xl') xl!: ElementRef;
}
Position
position docks the dialog to the top, bottom, or centre of the viewport. Top suits a system notice that shouldn't demand full attention; bottom reads as a mobile-style action sheet.
Centre position
The default — anchored to the centre of the viewport.
Top position
Useful for non-blocking notices near the page header.
Bottom position
A mobile-friendly action-sheet style, close to the thumb zone.
<aegov-button id="pos-center">Centre</aegov-button>
<aegov-button id="pos-top">Top</aegov-button>
<aegov-button id="pos-bottom">Bottom</aegov-button>
<aegov-modal id="modal-center" position="center" label="Centre modal">
<h3 class="font-bold text-xl mb-2">Centre position</h3>
<p class="text-base mb-6">The default — anchored to the centre of the viewport.</p>
<div class="flex justify-end"><aegov-button id="close-center">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-top" position="top" label="Top modal">
<h3 class="font-bold text-xl mb-2">Top position</h3>
<p class="text-base mb-6">Useful for non-blocking notices near the page header.</p>
<div class="flex justify-end"><aegov-button id="close-top">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-bottom" position="bottom" label="Bottom modal">
<h3 class="font-bold text-xl mb-2">Bottom position</h3>
<p class="text-base mb-6">A mobile-friendly action-sheet style, close to the thumb zone.</p>
<div class="flex justify-end"><aegov-button id="close-bottom">Close</aegov-button></div>
</aegov-modal>
<script>
['center','top','bottom'].forEach(p => {
const m = document.getElementById('modal-' + p);
document.getElementById('pos-' + p).addEventListener('click', () => m.show());
document.getElementById('close-' + p).addEventListener('click', () => m.close());
});
</script>
import { useRef, type ComponentRef } from 'react';
import { AegovButton, AegovModal } from '@aegov/designsystem-react';
const positions = [
{ key: 'center', label: 'Centre', body: 'The default — anchored to the centre of the viewport.' },
{ key: 'top', label: 'Top', body: 'Useful for non-blocking notices near the page header.' },
{ key: 'bottom', label: 'Bottom', body: 'A mobile-friendly action-sheet style, close to the thumb zone.' },
] as const;
export default function ModalPosition() {
const modals = useRef<Record<string, ComponentRef<typeof AegovModal> | null>>({});
return (
<>
<div className="flex flex-wrap gap-3">
{positions.map(p => (
<AegovButton key={p.key} onClick={() => modals.current[p.key]?.show()}>{p.label}</AegovButton>
))}
</div>
{positions.map(p => (
<AegovModal key={p.key} ref={(el) => { modals.current[p.key] = el; }} position={p.key} label={`${p.label} modal`}>
<h3 className="font-bold text-xl mb-2">{p.label} position</h3>
<p className="text-base mb-6">{p.body}</p>
<div className="flex justify-end">
<AegovButton onClick={() => modals.current[p.key]?.close()}>Close</AegovButton>
</div>
</AegovModal>
))}
</>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button @click="modalCenter?.show()">Centre</aegov-button>
<aegov-button @click="modalTop?.show()">Top</aegov-button>
<aegov-button @click="modalBottom?.show()">Bottom</aegov-button>
</div>
<aegov-modal ref="modalCenter" position="center" label="Centre modal">
<h3 class="font-bold text-xl mb-2">Centre position</h3>
<p class="text-base mb-6">The default — anchored to the centre of the viewport.</p>
<div class="flex justify-end"><aegov-button @click="modalCenter?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalTop" position="top" label="Top modal">
<h3 class="font-bold text-xl mb-2">Top position</h3>
<p class="text-base mb-6">Useful for non-blocking notices near the page header.</p>
<div class="flex justify-end"><aegov-button @click="modalTop?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalBottom" position="bottom" label="Bottom modal">
<h3 class="font-bold text-xl mb-2">Bottom position</h3>
<p class="text-base mb-6">A mobile-friendly action-sheet style, close to the thumb zone.</p>
<div class="flex justify-end"><aegov-button @click="modalBottom?.close()">Close</aegov-button></div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modalCenter = ref(null);
const modalTop = ref(null);
const modalBottom = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovModal } from '@aegov/designsystem-angular';
@Component({
selector: 'app-modal-position',
imports: [AegovButton, AegovModal],
template: `
<div class="flex flex-wrap gap-3">
<aegov-button (click)="center.show()">Centre</aegov-button>
<aegov-button (click)="top.show()">Top</aegov-button>
<aegov-button (click)="bottom.show()">Bottom</aegov-button>
</div>
<aegov-modal #center position="center" label="Centre modal">
<h3 class="font-bold text-xl mb-2">Centre position</h3>
<p class="text-base mb-6">The default — anchored to the centre of the viewport.</p>
<div class="flex justify-end"><aegov-button (click)="center.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #top position="top" label="Top modal">
<h3 class="font-bold text-xl mb-2">Top position</h3>
<p class="text-base mb-6">Useful for non-blocking notices near the page header.</p>
<div class="flex justify-end"><aegov-button (click)="top.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #bottom position="bottom" label="Bottom modal">
<h3 class="font-bold text-xl mb-2">Bottom position</h3>
<p class="text-base mb-6">A mobile-friendly action-sheet style, close to the thumb zone.</p>
<div class="flex justify-end"><aegov-button (click)="bottom.close()">Close</aegov-button></div>
</aegov-modal>
`,
})
export class ModalPositionComponent {
@ViewChild('center') center!: ElementRef;
@ViewChild('top') top!: ElementRef;
@ViewChild('bottom') bottom!: ElementRef;
}
Overlay opacity
overlay-opacity controls how much of the page behind the dialog is dimmed — light for a subtle wash, base (default) for balanced contrast, and dark for high-attention dialogs such as destructive confirmations.
Light backdrop
A gentle dim, suitable for low-stakes notices.
Base backdrop
The default — clear separation from the page without being heavy.
Dark backdrop
High contrast — use for destructive confirmations or critical alerts.
<aegov-button id="op-light">Light backdrop</aegov-button>
<aegov-button id="op-base">Base backdrop</aegov-button>
<aegov-button id="op-dark">Dark backdrop</aegov-button>
<aegov-modal id="modal-light" overlay-opacity="light" label="Light backdrop">
<h3 class="font-bold text-xl mb-2">Light backdrop</h3>
<p class="text-base mb-6">A gentle dim, suitable for low-stakes notices.</p>
<div class="flex justify-end"><aegov-button id="close-light">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-base-op" overlay-opacity="base" label="Base backdrop">
<h3 class="font-bold text-xl mb-2">Base backdrop</h3>
<p class="text-base mb-6">The default — clear separation from the page without being heavy.</p>
<div class="flex justify-end"><aegov-button id="close-base-op">Close</aegov-button></div>
</aegov-modal>
<aegov-modal id="modal-dark" overlay-opacity="dark" label="Dark backdrop">
<h3 class="font-bold text-xl mb-2">Dark backdrop</h3>
<p class="text-base mb-6">High contrast — use for destructive confirmations or critical alerts.</p>
<div class="flex justify-end"><aegov-button id="close-dark">Close</aegov-button></div>
</aegov-modal>
<script>
const map = { light: 'light', base: 'base-op', dark: 'dark' };
Object.entries(map).forEach(([key, id]) => {
const m = document.getElementById('modal-' + id);
document.getElementById('op-' + key).addEventListener('click', () => m.show());
document.getElementById('close-' + id).addEventListener('click', () => m.close());
});
</script>
import { useRef, type ComponentRef } from 'react';
import { AegovButton, AegovModal } from '@aegov/designsystem-react';
const opacities = [
{ key: 'light', label: 'Light backdrop', body: 'A gentle dim, suitable for low-stakes notices.' },
{ key: 'base', label: 'Base backdrop', body: 'The default — clear separation from the page without being heavy.' },
{ key: 'dark', label: 'Dark backdrop', body: 'High contrast — use for destructive confirmations or critical alerts.' },
] as const;
export default function ModalOverlayOpacity() {
const modals = useRef<Record<string, ComponentRef<typeof AegovModal> | null>>({});
return (
<>
<div className="flex flex-wrap gap-3">
{opacities.map(o => (
<AegovButton key={o.key} onClick={() => modals.current[o.key]?.show()}>{o.label}</AegovButton>
))}
</div>
{opacities.map(o => (
<AegovModal key={o.key} ref={(el) => { modals.current[o.key] = el; }} overlayOpacity={o.key} label={o.label}>
<h3 className="font-bold text-xl mb-2">{o.label}</h3>
<p className="text-base mb-6">{o.body}</p>
<div className="flex justify-end">
<AegovButton onClick={() => modals.current[o.key]?.close()}>Close</AegovButton>
</div>
</AegovModal>
))}
</>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button @click="modalLight?.show()">Light backdrop</aegov-button>
<aegov-button @click="modalBase?.show()">Base backdrop</aegov-button>
<aegov-button @click="modalDark?.show()">Dark backdrop</aegov-button>
</div>
<aegov-modal ref="modalLight" overlay-opacity="light" label="Light backdrop">
<h3 class="font-bold text-xl mb-2">Light backdrop</h3>
<p class="text-base mb-6">A gentle dim, suitable for low-stakes notices.</p>
<div class="flex justify-end"><aegov-button @click="modalLight?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalBase" overlay-opacity="base" label="Base backdrop">
<h3 class="font-bold text-xl mb-2">Base backdrop</h3>
<p class="text-base mb-6">The default — clear separation from the page without being heavy.</p>
<div class="flex justify-end"><aegov-button @click="modalBase?.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal ref="modalDark" overlay-opacity="dark" label="Dark backdrop">
<h3 class="font-bold text-xl mb-2">Dark backdrop</h3>
<p class="text-base mb-6">High contrast — use for destructive confirmations or critical alerts.</p>
<div class="flex justify-end"><aegov-button @click="modalDark?.close()">Close</aegov-button></div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modalLight = ref(null);
const modalBase = ref(null);
const modalDark = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovModal } from '@aegov/designsystem-angular';
@Component({
selector: 'app-modal-overlay-opacity',
imports: [AegovButton, AegovModal],
template: `
<div class="flex flex-wrap gap-3">
<aegov-button (click)="light.show()">Light backdrop</aegov-button>
<aegov-button (click)="base.show()">Base backdrop</aegov-button>
<aegov-button (click)="dark.show()">Dark backdrop</aegov-button>
</div>
<aegov-modal #light overlay-opacity="light" label="Light backdrop">
<h3 class="font-bold text-xl mb-2">Light backdrop</h3>
<p class="text-base mb-6">A gentle dim, suitable for low-stakes notices.</p>
<div class="flex justify-end"><aegov-button (click)="light.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #base overlay-opacity="base" label="Base backdrop">
<h3 class="font-bold text-xl mb-2">Base backdrop</h3>
<p class="text-base mb-6">The default — clear separation from the page without being heavy.</p>
<div class="flex justify-end"><aegov-button (click)="base.close()">Close</aegov-button></div>
</aegov-modal>
<aegov-modal #dark overlay-opacity="dark" label="Dark backdrop">
<h3 class="font-bold text-xl mb-2">Dark backdrop</h3>
<p class="text-base mb-6">High contrast — use for destructive confirmations or critical alerts.</p>
<div class="flex justify-end"><aegov-button (click)="dark.close()">Close</aegov-button></div>
</aegov-modal>
`,
})
export class ModalOverlayOpacityComponent {
@ViewChild('light') light!: ElementRef;
@ViewChild('base') base!: ElementRef;
@ViewChild('dark') dark!: ElementRef;
}
Preventing accidental dismissal
Set is-close-with-overlay="false" to stop a backdrop click from closing the dialog — useful for a form where losing progress by an accidental click outside would be costly. Escape still closes the dialog either way; it always closes for accessibility and cannot be disabled.
Update mobile number
<aegov-button id="open-form">Update mobile number</aegov-button>
<aegov-modal id="form-modal" is-close-with-overlay="false" label="Update mobile number">
<h3 id="form-title" class="font-bold text-xl mb-4">Update mobile number</h3>
<aegov-form-field>
<aegov-label>New mobile number</aegov-label>
<aegov-input field-id="form-mobile" type="tel" placeholder="+971 50 000 0000"></aegov-input>
</aegov-form-field>
<div class="flex justify-end gap-3 mt-6">
<aegov-button variant="secondary" id="form-cancel">Cancel</aegov-button>
<aegov-button id="form-save">Save</aegov-button>
</div>
</aegov-modal>
<script>
const m = document.getElementById('form-modal');
document.getElementById('open-form').addEventListener('click', () => m.show());
document.getElementById('form-cancel').addEventListener('click', () => m.close());
document.getElementById('form-save').addEventListener('click', () => m.close());
</script>
import { useRef } from 'react';
import { AegovButton, AegovModal, AegovFormField, AegovLabel, AegovInput } from '@aegov/designsystem-react';
export default function ModalNoOverlayClose() {
const modalRef = useRef<HTMLAegovModalElement>(null);
return (
<>
<AegovButton onClick={() => modalRef.current?.show()}>Update mobile number</AegovButton>
<AegovModal ref={modalRef} isCloseWithOverlay={false} label="Update mobile number">
<h3 id="form-title" className="font-bold text-xl mb-4">Update mobile number</h3>
<AegovFormField>
<AegovLabel>New mobile number</AegovLabel>
<AegovInput fieldId="form-mobile" type="tel" placeholder="+971 50 000 0000" />
</AegovFormField>
<div className="flex justify-end gap-3 mt-6">
<AegovButton variant="secondary" onClick={() => modalRef.current?.close()}>Cancel</AegovButton>
<AegovButton onClick={() => modalRef.current?.close()}>Save</AegovButton>
</div>
</AegovModal>
</>
);
}
<template>
<aegov-button @click="modal?.show()">Update mobile number</aegov-button>
<aegov-modal ref="modal" is-close-with-overlay="false" label="Update mobile number">
<h3 id="form-title" class="font-bold text-xl mb-4">Update mobile number</h3>
<aegov-form-field>
<aegov-label>New mobile number</aegov-label>
<aegov-input field-id="form-mobile" type="tel" placeholder="+971 50 000 0000"></aegov-input>
</aegov-form-field>
<div class="flex justify-end gap-3 mt-6">
<aegov-button variant="secondary" @click="modal?.close()">Cancel</aegov-button>
<aegov-button @click="modal?.close()">Save</aegov-button>
</div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modal = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovModal, AegovFormField, AegovLabel, AegovInput } from '@aegov/designsystem-angular';
@Component({
selector: 'app-modal-no-overlay-close',
imports: [AegovButton, AegovModal, AegovFormField, AegovLabel, AegovInput],
template: `
<aegov-button (click)="modal.show()">Update mobile number</aegov-button>
<aegov-modal #modal [isCloseWithOverlay]="false" label="Update mobile number">
<h3 id="form-title" class="font-bold text-xl mb-4">Update mobile number</h3>
<aegov-form-field>
<aegov-label>New mobile number</aegov-label>
<aegov-input field-id="form-mobile" type="tel" placeholder="+971 50 000 0000"></aegov-input>
</aegov-form-field>
<div class="flex justify-end gap-3 mt-6">
<aegov-button variant="secondary" (click)="modal.close()">Cancel</aegov-button>
<aegov-button (click)="modal.close()">Save</aegov-button>
</div>
</aegov-modal>
`,
})
export class ModalNoOverlayCloseComponent {
@ViewChild('modal') modal!: ElementRef;
}
Composing with Form Field
A modal drops naturally around any other component — here, an aegov-form-field for a short, single-field update. Closing with unsaved changes is one of the clearest cases for listening to aegovModalBeforeClose. Save and Cancel close the modal with close(), which fires the same event, so the example keeps the saved note apart from the draft and only cancels the close while the two differ — Save stores the draft first, Cancel reverts it. The guard covers a backdrop click and close(); Escape always closes the modal without firing it (WCAG 2.1.2).
Edit profile note
<aegov-button id="open-guarded">Edit profile note</aegov-button>
<aegov-modal id="guarded-modal" label="Edit profile note">
<h3 id="guarded-title" class="font-bold text-xl mb-4">Edit profile note</h3>
<aegov-form-field>
<aegov-label>Note</aegov-label>
<aegov-textarea field-id="guarded-note" placeholder="Add a note visible only to case officers."></aegov-textarea>
</aegov-form-field>
<div class="flex justify-end gap-3 mt-6">
<aegov-button variant="secondary" id="guarded-cancel">Cancel</aegov-button>
<aegov-button id="guarded-save">Save</aegov-button>
</div>
</aegov-modal>
<script>
const m = document.getElementById('guarded-modal');
let savedNote = '';
// aegov-textarea reflects field-id to a real id only after it
// hydrates, so look it up fresh at use-time rather than caching
// a reference before hydration has necessarily finished.
document.getElementById('open-guarded').addEventListener('click', () => m.show());
document.getElementById('guarded-save').addEventListener('click', () => {
savedNote = document.getElementById('guarded-note').value;
m.close();
});
// Runs for a backdrop click and for close(). Escape always closes (WCAG 2.1.2).
m.addEventListener('aegovModalBeforeClose', (e) => {
if (document.getElementById('guarded-note').value !== savedNote) {
e.preventDefault();
window.alert('You have unsaved changes. Choose Save to keep them or Cancel to discard them.');
}
});
document.getElementById('guarded-cancel').addEventListener('click', () => {
document.getElementById('guarded-note').value = savedNote;
m.close();
});
</script>
import { useRef } from 'react';
import { AegovButton, AegovModal, AegovFormField, AegovLabel, AegovTextarea } from '@aegov/designsystem-react';
export default function ModalFormField() {
const modalRef = useRef<HTMLAegovModalElement>(null);
const textareaRef = useRef<HTMLAegovTextareaElement>(null);
// Refs, not state: onAegovModalBeforeClose must see the latest text at once.
const draftRef = useRef('');
const savedNoteRef = useRef('');
const cancel = () => {
draftRef.current = savedNoteRef.current;
if (textareaRef.current) textareaRef.current.value = savedNoteRef.current;
modalRef.current?.close();
};
const save = () => {
savedNoteRef.current = draftRef.current;
modalRef.current?.close();
};
return (
<>
<AegovButton onClick={() => modalRef.current?.show()}>Edit profile note</AegovButton>
<AegovModal
ref={modalRef}
label="Edit profile note"
// Runs for a backdrop click and for close(). Escape always closes (WCAG 2.1.2).
onAegovModalBeforeClose={(e) => {
if (draftRef.current !== savedNoteRef.current) {
e.preventDefault();
window.alert('You have unsaved changes. Choose Save to keep them or Cancel to discard them.');
}
}}
>
<h3 id="guarded-title" className="font-bold text-xl mb-4">Edit profile note</h3>
<AegovFormField>
<AegovLabel>Note</AegovLabel>
<AegovTextarea
ref={textareaRef}
fieldId="guarded-note"
placeholder="Add a note visible only to case officers."
onAegovTextareaValue={(e) => { draftRef.current = e.detail.value; }}
/>
</AegovFormField>
<div className="flex justify-end gap-3 mt-6">
<AegovButton variant="secondary" onClick={cancel}>Cancel</AegovButton>
<AegovButton onClick={save}>Save</AegovButton>
</div>
</AegovModal>
</>
);
}
<template>
<aegov-button @click="modal?.show()">Edit profile note</aegov-button>
<aegov-modal ref="modal" label="Edit profile note" @aegovModalBeforeClose="onBeforeClose">
<h3 id="guarded-title" class="font-bold text-xl mb-4">Edit profile note</h3>
<aegov-form-field>
<aegov-label>Note</aegov-label>
<aegov-textarea field-id="guarded-note" placeholder="Add a note visible only to case officers." :value="draft" @aegovTextareaValue="draft = $event.detail.value"></aegov-textarea>
</aegov-form-field>
<div class="flex justify-end gap-3 mt-6">
<aegov-button variant="secondary" @click="cancel">Cancel</aegov-button>
<aegov-button @click="save">Save</aegov-button>
</div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modal = ref(null);
const savedNote = ref('');
const draft = ref('');
// Runs for a backdrop click and for close(). Escape always closes (WCAG 2.1.2).
function onBeforeClose(e) {
if (draft.value !== savedNote.value) {
e.preventDefault();
window.alert('You have unsaved changes. Choose Save to keep them or Cancel to discard them.');
}
}
function save() {
savedNote.value = draft.value;
modal.value?.close();
}
function cancel() {
draft.value = savedNote.value;
modal.value?.close();
}
</script>
import { Component, ViewChild } from '@angular/core';
import { AegovButton, AegovModal, AegovFormField, AegovLabel, AegovTextarea } from '@aegov/designsystem-angular';
@Component({
selector: 'app-modal-form-field',
imports: [AegovButton, AegovModal, AegovFormField, AegovLabel, AegovTextarea],
template: `
<aegov-button (click)="modal.show()">Edit profile note</aegov-button>
<aegov-modal #modal label="Edit profile note" (aegovModalBeforeClose)="onBeforeClose($event)">
<h3 id="guarded-title" class="font-bold text-xl mb-4">Edit profile note</h3>
<aegov-form-field>
<aegov-label>Note</aegov-label>
<aegov-textarea field-id="guarded-note" placeholder="Add a note visible only to case officers." [value]="draft" (aegovTextareaValue)="draft = $event.detail.value"></aegov-textarea>
</aegov-form-field>
<div class="flex justify-end gap-3 mt-6">
<aegov-button variant="secondary" (click)="cancel()">Cancel</aegov-button>
<aegov-button (click)="save()">Save</aegov-button>
</div>
</aegov-modal>
`,
})
export class ModalFormFieldComponent {
@ViewChild('modal') modal!: AegovModal;
savedNote = '';
draft = '';
// Runs for a backdrop click and for close(). Escape always closes (WCAG 2.1.2).
onBeforeClose(e: Event) {
if (this.draft !== this.savedNote) {
e.preventDefault();
window.alert('You have unsaved changes. Choose Save to keep them or Cancel to discard them.');
}
}
save() {
this.savedNote = this.draft;
this.modal.close();
}
cancel() {
this.draft = this.savedNote;
this.modal.close();
}
}
RTL support
On open, aegov-modal resolves its direction at its declared position — from the nearest dir ancestor, else <html dir> — and pins it as dir on the host until it closes. A dir="rtl" on a wrapper therefore still applies even if the modal has to move out of a trapping ancestor. Setting dir="rtl" directly on aegov-modal, as below, also works and is never overwritten.
حذف هذا الطلب؟
سيتم حذف مسوّدة طلبك لخدمة تجديد الهوية الإماراتية بشكل دائم. لا يمكن التراجع عن هذا الإجراء.
<aegov-button id="open-rtl">حذف الطلب</aegov-button>
<aegov-modal id="rtl-modal" dir="rtl" label="حذف هذا الطلب؟">
<h3 id="rtl-title" class="font-bold text-xl mb-2">حذف هذا الطلب؟</h3>
<p class="text-base mb-6">سيتم حذف مسوّدة طلبك لخدمة تجديد الهوية الإماراتية بشكل دائم. لا يمكن التراجع عن هذا الإجراء.</p>
<div class="flex justify-end gap-3">
<aegov-button variant="secondary" id="rtl-cancel">إلغاء</aegov-button>
<aegov-button variant="danger" id="rtl-confirm">حذف</aegov-button>
</div>
</aegov-modal>
<script>
const m = document.getElementById('rtl-modal');
document.getElementById('open-rtl').addEventListener('click', () => m.show());
document.getElementById('rtl-cancel').addEventListener('click', () => m.close());
document.getElementById('rtl-confirm').addEventListener('click', () => m.close());
</script>
import { useRef } from 'react';
import { AegovButton, AegovModal } from '@aegov/designsystem-react';
export default function RtlModal() {
const modalRef = useRef<HTMLAegovModalElement>(null);
return (
<>
<AegovButton onClick={() => modalRef.current?.show()}>حذف الطلب</AegovButton>
<AegovModal ref={modalRef} dir="rtl" label="حذف هذا الطلب؟">
<h3 id="rtl-title" className="font-bold text-xl mb-2">حذف هذا الطلب؟</h3>
<p className="text-base mb-6">سيتم حذف مسوّدة طلبك لخدمة تجديد الهوية الإماراتية بشكل دائم. لا يمكن التراجع عن هذا الإجراء.</p>
<div className="flex justify-end gap-3">
<AegovButton variant="secondary" onClick={() => modalRef.current?.close()}>إلغاء</AegovButton>
<AegovButton variant="danger" onClick={() => modalRef.current?.close()}>حذف</AegovButton>
</div>
</AegovModal>
</>
);
}
<template>
<aegov-button @click="modal?.show()">حذف الطلب</aegov-button>
<aegov-modal ref="modal" dir="rtl" label="حذف هذا الطلب؟">
<h3 id="rtl-title" class="font-bold text-xl mb-2">حذف هذا الطلب؟</h3>
<p class="text-base mb-6">سيتم حذف مسوّدة طلبك لخدمة تجديد الهوية الإماراتية بشكل دائم. لا يمكن التراجع عن هذا الإجراء.</p>
<div class="flex justify-end gap-3">
<aegov-button variant="secondary" @click="modal?.close()">إلغاء</aegov-button>
<aegov-button variant="danger" @click="modal?.close()">حذف</aegov-button>
</div>
</aegov-modal>
</template>
<script setup>
import { ref } from 'vue';
const modal = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovModal } from '@aegov/designsystem-angular';
@Component({
selector: 'app-rtl-modal',
imports: [AegovButton, AegovModal],
template: `
<aegov-button (click)="modal.show()">حذف الطلب</aegov-button>
<aegov-modal #modal dir="rtl" label="حذف هذا الطلب؟">
<h3 id="rtl-title" class="font-bold text-xl mb-2">حذف هذا الطلب؟</h3>
<p class="text-base mb-6">سيتم حذف مسوّدة طلبك لخدمة تجديد الهوية الإماراتية بشكل دائم. لا يمكن التراجع عن هذا الإجراء.</p>
<div class="flex justify-end gap-3">
<aegov-button variant="secondary" (click)="modal.close()">إلغاء</aegov-button>
<aegov-button variant="danger" (click)="modal.close()">حذف</aegov-button>
</div>
</aegov-modal>
`,
})
export class RtlModalComponent {
@ViewChild('modal') modal!: ElementRef;
}
Usage
Here is the recommended usage of a modal on any website or application. These are recommended usage guides, however the developer must use the best practices of web and application development to accurately use this component.
Always give the dialog an accessible name
Set label to the text of the visible heading inside the modal. Without it, screen readers announce only "dialog".
Set dir="rtl" on the page, a wrapper, or aegov-modal itself for an RTL dialog
On open, the modal pins the direction it resolves at its declared position as dir on the host (removed again on close), so a wrapper's dir="rtl" still applies even if the modal has to move out of a trapping ancestor. A dir you set on aegov-modal yourself is never overwritten.
Listen for aegovModalBeforeClose to guard unsaved changes
Call event.preventDefault() inside the handler to keep the modal open, then prompt the user in place. This covers a backdrop click and a programmatic close() — Escape always closes the modal (WCAG 2.1.2); see the Keyboard support notes.
Pair overlay-opacity="dark" with a danger-styled confirm button for destructive actions
The heavier backdrop visually matches the weight of an irreversible action like a delete confirmation.
Don't rely on aegovModalBeforeClose to stop Escape from closing the dialog
Escape always closes the modal without emitting aegovModalBeforeClose at all, per WCAG 2.1.2 — a handler that calls preventDefault() protects against a backdrop click or a programmatic close, but never against Escape.
Don't nest a multi-step form inside a modal
Keep dialog content to a single task. A workflow that needs several steps is better served by a dedicated page or a wizard, where progress and back-navigation are easier to reason about than inside an overlay.
API reference
The following are the properties and references of a modal
aegov-modal properties
| Attribute | Description | Type | Default |
|---|---|---|---|
| DOM |
| auto-generated |
| Whether the modal is currently visible. Can be set from the start — the component correctly opens (focus trap, scroll lock, Escape listener) even when declared open on load, not only on a later change. |
|
|
| Whether clicking the backdrop closes the modal. |
|
|
| Lock page scroll while the modal is open. Reference-counted, so a second open overlay keeps scroll locked correctly until the last one closes. |
|
|
| Backdrop dim level. |
|
|
| Where the dialog docks in the viewport. |
|
|
| Fixed panel width (300px, 600px, 800px or 1140px, capped at the viewport width) plus padding and corner-radius scale, mirroring |
|
|
| Apply inner content padding. Turn off for full-bleed content such as a banner image. |
|
|
| Accessible name for the dialog, set as |
| — |
Slots
| Slot | Description |
|---|---|
(default) | The dialog content — heading, body text, and any action buttons. There is no separate header/body/footer slot; compose the layout with regular HTML inside the default slot. |
Events
| Event | Detail | Description |
|---|---|---|
|
| Fired synchronously when opening starts, before focus moves into the dialog. |
|
| Fired once the modal has finished closing and focus has been returned to the trigger. |
|
| Cancellable — call |
|
| Fired for every click that reaches the full-viewport container — including clicks inside the dialog panel — regardless of whether |
|
| Fired when |
Methods
| Method | Returns | Description |
|---|---|---|
|
| Open the modal. |
|
| Close the modal (fires the cancellable |
|
| Flip the open state. Closing this way skips |
Pass-through attributes
| Attribute | Notes | Forwards to |
|---|---|---|
| Forwarded to the inner | inner dialog element |
other | Forwarded to the inner | inner dialog element |
| Not forwarded. Use | n/a |
| Applied to the host element. Limited reach — the backdrop and dialog markup live inside a real shadow root, so page-level CSS cannot style them directly. | host |
Notes
The following notes are applicable of this component.
Built-in accessibility
- The dialog renders with
role="dialog"andaria-modal="true"— confirmed reaching the real inner dialog element regardless of how the modal was opened. - Focus moves to the first focusable element inside the dialog as soon as it opens — confirmed for both a declarative
is-open="true"and an imperativeshow()call. If the dialog has no focusable children, the dialog container itself receives focus so assistive technology still announces it. Tab/Shift + Tabcorrectly wrap focus within just the dialog's own focusable elements in both directions, without ever reaching the page behind it.- On close, focus is returned to the exact element that had focus when the dialog opened.
- Page scroll is locked while the dialog is open (reference-counted, so a second, nested overlay keeps scroll locked until the last one closes) and correctly released on close.
- The modal stays where it is declared. Only while it is open, and only if an ancestor would trap its fixed-position layers (a
transform,filter, stacking context, or hidden ancestor), it moves out of that ancestor — todocument.bodyas a last resort — and returns on close. Its z-index comes from a shared overlay manager, so it stacks above the page and above any overlay opened before it. - On open, the direction resolved at its declared position is pinned as
diron the host, so the dialog keeps an ancestor'sdir="rtl"even after a move.
Developer responsibilities
- Always set the
labelprop — without it, the component logs a console warning, and screen readers announce only "dialog". Do not rely onaria-labelledbyon the host: the dialog lives in a shadow root and cannot resolve anidin your page. - Make the heading state the action plainly, so the name alone conveys it.
aria-describedbyon the host has the same shadow-root limitation and does not link supporting body text. - Listen for
aegovModalBeforeCloseand callpreventDefault()when the user has unsaved changes, then prompt them in place rather than silently discarding data. - For an RTL dialog, set
dir="rtl"on the page, an ancestor, oraegov-modalitself — the modal pins the direction it resolves on open, so any of these is kept.
Keyboard support
| Key | Function |
|---|---|
Enter, Space |
Activate the focused button or control. |
Tab |
Move focus to the next focusable element inside the dialog, wrapping to the first after the last. |
Shift + Tab |
Move focus to the previous focusable element, wrapping to the last after the first. |
Escape |
Close the dialog immediately and return focus to the trigger. With overlays stacked, only the top one responds to Escape and Tab. Escape always closes and does not fire the cancellable aegovModalBeforeClose event — confirmed live with a listener that calls preventDefault() on aegovModalBeforeClose, which stops a backdrop click from closing the dialog but has no effect on Escape. Build any "are you sure you want to lose this?" guard around the backdrop-click and programmatic-close paths, not around blocking Escape itself. |