<content-overlay>
A dialog that opens over the page, or inside another element, and keeps keyboard focus inside it while open.
import '@content-blocks/js/components/content-overlay';Examples
A dialog
A button whose href points at the overlay opens it. Focus stays inside until it closes.
<content-button href="#example-dialog">Read the prophecy</content-button>
<content-overlay id="example-dialog" size="mini">
<content-line slot="header" tag="h3">The prophecy</content-line>
<script slot="content" type="text/template">
<p>When the wolf swallows the sun and the serpent leaves the sea, the Warden will return.</p>
</script>
</content-overlay>content-button a {
padding: 0.5rem 1rem;
color: #fff;
text-decoration: none;
background: #1d4ed8;
}// $ npm install @content-blocks/js
import '@content-blocks/js/components/content-button';
import '@content-blocks/js/components/content-overlay';
import '@content-blocks/js/components/content-line';<script type="module"
src="https://cdn.jsdelivr.net/npm/@content-blocks/js/dist/content-blocks/content-blocks.esm.js"></script>Anatomy
Content goes into the component's slots, chosen with the slot attribute on each child.
flowchart LR root["#lt;content-overlay#gt;"]:::component root --> s0["<b>no slot (default)</b><br/>The default slot"] root --> s1["<b>slot=#quot;closeButton#quot;</b><br/>Contents of the overlay close button."] root --> s2["<b>slot=#quot;content#quot;</b><br/>Contents that sit inside the overlay."] root --> s3["<b>slot=#quot;header#quot;</b><br/>This is adjacent to the close button, usually a header or title for t…"] classDef component fill:#141413,color:#faf9f5,stroke:#141413
| Slot | What goes in it |
|---|---|
(default) | The default slot |
slot="closeButton" | Contents of the overlay close button. |
slot="content" | Contents that sit inside the overlay. |
slot="header" | This is adjacent to the close button, usually a header or title for the overlay. |
Properties
Set them as attributes. Those marked responsive take a value per breakpoint, separated by pipes and named or in order: 1|tablet=2 or 1|2. Seeresponsive values.
| Attribute | Type | Default | Description |
|---|---|---|---|
classesresponsive | String | – | Classes to add to the component. Use pipes for different classes per breakpoint, by name or in order: classes="stacked|laptop=side-by-side". |
close-title | String | 'Close Overlay' | Title attribute value for the close button. |
fillresponsive | String | 'body' | What the overlay covers. "body", the default, covers the whole screen. A CSS selector, such as "#hero", covers that element instead: the overlay moves into it when it opens. Use pipes to cover the screen on phones and an element on wider screens: fill="body|#hero". |
full-screenresponsive | Boolean | 'true' | Not documented yet |
horizontalresponsive | Select | 'center' | A pipe delimited setting for horizontal alignment. This only applies when fullscreen mode is activated. |
label | String | – | The accessible name of the dialog. Only needed when there is no header slot, which names it otherwise. |
openresponsive | Boolean | 'false' | Not documented yet |
paddingresponsive | String | – | Padding around the component, written as CSS padding. Use pipes for different padding per breakpoint, by name or in order: padding="1rem|tablet=2rem 4rem" or padding="1rem|2rem 4rem|3rem 5rem 4rem". |
vertical | Select | 'center' | A pipe delimited setting for vertical alignment. This only applies when fullscreen mode is activated. |
Events and methods
sequenceDiagram participant Page participant C as content-overlay Page->>C: toggle event Page->>C: open event Page->>C: close event Page->>C: closeOverlay() Page->>C: openOverlay() C-->>Page: contentOverlayActivated C-->>Page: contentOverlayDeactivated
| Event | Detail | Description |
|---|---|---|
contentOverlayActivated | HTMLElement | Not documented yet |
contentOverlayDeactivated | HTMLElement | Not documented yet |
| Method | Description |
|---|---|
closeOverlay() => Promise<void> | Not documented yet |
openOverlay() => Promise<void> | Not documented yet |
