game-modal

Coordinates one direct dialog child. Use native show-modal commands or the open attribute after upgrade. Escape and method=dialog preserve native behavior. A missing dialog is inert until inserted.

Examples

Modal dialog

Open the native dialog. Close it with the form button or Escape to return focus to the opener.

Modal dialog HTML
<button type="button" command="show-modal" commandfor="demo-inventory">Open inventory</button>
<game-modal>
	<dialog id="demo-inventory" aria-labelledby="inventory-title">
		<h3 id="inventory-title">Inventory</h3>
		<p>One spare battery.</p>
		<form method="dialog"><button autofocus>Close inventory</button></form>
	</dialog>
</game-modal>

Inventory

One spare battery.

Initially visible dialog

The native open attribute shows a nonmodal dialog on load. Close it with its form button.

Initially visible dialog HTML
<game-modal open>
	<dialog open aria-label="Briefing note" style="position:static;margin:0">
		<p>Shields recharge between sectors.</p>
		<form method="dialog"><button>Dismiss briefing note</button></form>
	</dialog>
</game-modal>

Shields recharge between sectors.

API

Attributes
NameType or defaultBehavior
open boolean Presence opens the dialog, removal closes it. Reflected from native toggles. At initialization an already-open native dialog is adopted.
Emitted events
NameType or defaultBehavior
game-modal-change CustomEvent<{ open: boolean }> Bubbles and is composed. Emitted for a changed open state after initialization. Native toggle notifications can coalesce.

Listened-for events

None.

CSS custom properties

None.

View the Game Kit manifest