sgds-components-modal
SGDS Modal Component Skill
<sgds-modal> renders a dialog overlay that traps focus until dismissed. Use it for confirmations, alerts, or focused tasks that require user attention before continuing.
Prerequisites
See sgds-components-setup for installation and framework integration (React 19+ vs React ≤18, Vue, Angular).
No CSS styling modifications — custom properties and CSS parts are not exposed on this component.
Quick Decision Guide
Size?
- Default →
size="md"(default) - Small →
size="sm"/ Large →size="lg"/ Extra large →size="xl"/ Full screen →size="fullscreen"
Prevent closing on overlay/Esc? → Listen for sgds-close and call event.preventDefault()
Disable open/close animation? → Add noAnimation
Open/close programmatically? → Use the show() and hide() methods
<!-- Basic modal triggered by a button -->
<sgds-button id="open-modal">Open Modal</sgds-button>
<sgds-modal id="my-modal">
<h2 slot="title">Modal Title</h2>
<p slot="description">Brief description of what this modal is for.</p>
<p>Main content goes in the default slot. Forms, text, or any body content belongs here.</p>
<sgds-button slot="footer" variant="link" id="close-modal">Cancel</sgds-button>
<sgds-button slot="footer" variant="primary">Confirm</sgds-button>
</sgds-modal>
<script>
document.getElementById("open-modal").addEventListener("click", () => {
document.getElementById("my-modal").show();
});
document.getElementById("close-modal").addEventListener("click", () => {
document.getElementById("my-modal").hide();
});
</script>
<!-- Prevent close from overlay/keyboard — require explicit button press -->
<sgds-modal id="confirm-modal">
<h2 slot="title">Delete Item?</h2>
<p>This action cannot be undone.</p>
<sgds-button slot="footer" variant="link" id="cancel-delete">Cancel</sgds-button>
<sgds-button slot="footer" variant="danger" id="confirm-delete">Delete</sgds-button>
</sgds-modal>
<script>
document.getElementById("confirm-modal").addEventListener("sgds-close", e => {
if (e.detail.source !== "close-button") {
e.preventDefault();
}
});
</script>
<!-- Full screen modal -->
<sgds-modal size="fullscreen">
<h2 slot="title">Full Screen Modal</h2>
<p>Content that benefits from maximum screen real estate.</p>
</sgds-modal>
API Summary
| Attribute | Type | Default | Purpose |
|---|---|---|---|
open |
boolean | false |
Controls modal visibility; reflects when using show()/hide() |
size |
sm | md | lg | xl | fullscreen |
md |
Size of the modal dialog |
noAnimation |
boolean | false |
Disables open/close animations |
Slots
| Slot | Purpose |
|---|---|
title |
Modal heading |
description |
Brief description below the title |
| (default) | Main body content |
footer |
Footer area; typically holds action buttons |
Events
| Event | Cancelable | Detail | When |
|---|---|---|---|
sgds-show |
No | — | Modal begins opening |
sgds-after-show |
No | — | Modal fully open (animation complete) |
sgds-hide |
No | — | Modal begins closing |
sgds-after-hide |
No | — | Modal fully closed (animation complete) |
sgds-close |
Yes | { source: 'close-button' | 'overlay' | 'keyboard' } |
User attempts to close — call event.preventDefault() to keep it open |
Public Methods
| Method | Description |
|---|---|
show() |
Opens the modal |
hide() |
Closes the modal |
For AI agents:
- Use
show()/hide()methods to open/close programmatically; theopenattribute reflects the current state. sgds-closeis cancelable — callevent.preventDefault()to prevent closing. Checkevent.detail.sourcefor'close-button','overlay', or'keyboard'to apply conditional logic.- Place action buttons in the
footerslot — typically a cancel/link button and a primary action button. - Modal always renders with a built-in close button in the header unless controlled via the
sgds-closeevent. - Footer buttons that close the modal must call
modal.hide()explicitly — they do not auto-close the modal.
More from govtechsg/sgds-web-component
sgds-components
Complete reference for all SGDS web components including installation and framework integration. Use when users ask about any <sgds-*> component — accordion, alert, badge, breadcrumb, button, card, checkbox, close-button, combo-box, datepicker, description-list, divider, drawer, dropdown, file-upload, footer, icon, icon-button, icon-card, icon-list, image-card, input, link, mainnav, masthead, modal, overflow-menu, pagination, progress-bar, quantity-toggle, radio, select, sidebar, sidenav, skeleton, spinner, stepper, subnav, switch, system-banner, tab, table, table-of-contents, textarea, thumbnail-card, toast, or tooltip. Also covers React 19+, React ≤18, Vue, Angular, and Next.js integration.
58sgds-theming
Customising the visual theme of an SGDS application — product brand colours, day/night mode, and font. Use when users ask about changing the primary colour, theming their app, enabling dark mode, night mode, overriding CSS tokens, or customising the font. Apply this skill whenever theming, branding, or CSS token overrides are mentioned.
55sgds-workflow
ALWAYS use this skill when building UI with @govtechsg/sgds-web-component or when a user mentions SGDS or Singapore Design System — even if they don't explicitly ask for help. This is the mandatory entry point for all SGDS development: it guides you to the right skill for setup, components, utilities, forms, theming, page layouts, block templates, and data visualisation. Read this before writing any SGDS application code.
53sgds-data-visualisation
Use this skill when users ask about data visualisation, charts, graphs, or dashboards in an SGDS application. Covers ECharts setup and applying the SGDS colour palette to charts.
53sgds-forms
Use this skill when users ask about form validation in SGDS, hasFeedback prop, constraint validation, custom validation, noValidate, setInvalid, form submission, or reading FormData from SGDS form components.
53sgds-getting-started
Starting point for any new application built with the SGDS web component library. Apply this skill first whenever a user is bootstrapping a new SGDS project, setting up a new app, or asking where to begin with SGDS. Covers font setup, foundation CSS, utilities, components, and app layout in the correct order.
53