Dialog
2 Dialog variations from the W3C ARIA Authoring Practices Guide.
Dialog (Date Picker)
A native button opens a modal calendar beside a plain date text field. Choosing a date updates the field and the button’s accessible name; cancellation leaves the original value intact.
Example
Date format: mm/dd/yyyy
Keyboard interaction
Activate Choose date with Enter or Space. Arrows, Home/End and PageUp/PageDown navigate dates; add Shift to PageUp/PageDown to change year. Enter or Space selects a day. Escape cancels. Tab stays within the dialog.
Example HTML
<axxy-scope>
<div role="group" aria-label="Visit date picker" aria-roledescription="datepicker">
<label for="dialog-date">Visit date</label>
<input id="dialog-date" aria-describedby="dialog-date-format" placeholder="mm/dd/yyyy" value="02/28/2024">
<button type="button" aria-label="Choose date">Choose date</button>
<p id="dialog-date-format">Date format: mm/dd/yyyy</p>
<dialog>
<h3>Choose a visit date</h3>
<div>
<button type="button">Previous year</button>
<button type="button">Previous month</button>
<button type="button">Next month</button>
<button type="button">Next year</button>
</div>
<h4></h4>
<table aria-describedby="dialog-date-help">
<thead>
<tr>
<th scope="col" abbr="Sunday">Su</th>
<th scope="col" abbr="Monday">Mo</th>
<th scope="col" abbr="Tuesday">Tu</th>
<th scope="col" abbr="Wednesday">We</th>
<th scope="col" abbr="Thursday">Th</th>
<th scope="col" abbr="Friday">Fr</th>
<th scope="col" abbr="Saturday">Sa</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p id="dialog-date-help">Use arrows to move by day or week. Home and End move within the week. Page Up and Page Down change month; add Shift to change year.</p>
<button type="button">Cancel</button>
<button type="button">OK</button>
</dialog>
</div>
</axxy-scope>Dialog (Modal)
Native modal dialogs provide background inertness, nested confirmation, and focus return.
Example
Keyboard interaction
Enter opens the dialog. Tab/Shift+Tab stay inside. Escape closes the top dialog and returns focus.
Example HTML
<axxy-scope>
<button type="button">Edit address</button>
<dialog>
<h2>Edit address</h2>
<label>
Street
<input autofocus>
</label>
<label>
City
<input>
</label>
<button type="button" aria-controls="demo-nested">Review</button>
<button type="button">Cancel</button>
<dialog id="demo-nested">
<h2>Review changes</h2>
<p>Your address is ready to save.</p>
<button type="button" autofocus>Back to editing</button>
</dialog>
</dialog>
</axxy-scope>