Component · top layer
Sidepanel and Sheet
The modal dialog along an edge, or from the bottom on a phone. Same behaviour, different placement.
Astro
---
import Sidepanel from '@subfloor/astro/Sidepanel.astro'
---
<button command="show-modal" commandfor="filters">Filters</button>
<!-- placement: "end" (default) | "start" | "bottom" (a sheet) -->
<Sidepanel id="filters" title="Filters" placement="end">
…
</Sidepanel>React has the same component: <Sidepanel placement="bottom"> from @subfloor/react. The markup is the Modal's with another data-placement.
Behaviour
- Everything the Modal does: scroll lock, focus, Escape, backdrop, inert page.
- A sidepanel is the full dynamic viewport height (
100dvh), so the mobile address bar does not cut it off. - A sheet is as tall as its content up to
--sf-sheet-max-height; its body scrolls and never hands the scroll on to the page (overscroll-behavior: contain). It keeps clear of the home indicator (env(safe-area-inset-bottom)). - On a phone or tablet, swipe a sheet down by its bar or header to close it (reason
swipe): past 100px, past half of a shorter sheet, or with a quick flick. Otherwise it goes back. Its content only scrolls. The close button, Escape and the backdrop still work. - Turn swiping off for one sheet with
swipeToClose={false}(React and Astro) ordata-swipe="off"(plain HTML). It needs the script and.sf-dialog__header: without the script there is no bar. It is on where(pointer: coarse)matches, and only a touch moves the sheet, never a mouse. A swipe cannot start on a field in the header. - It slides in from its edge; under reduced motion it appears at once, and a swiped sheet follows the finger but does not animate after it.
Beside a list
With inlineAt (a media query; data-inline-at in plain HTML) the sidepanel opens beside the page's content where the query matches, in its own place in your layout. It is still a dialog, but not modal: no backdrop, no scroll lock, and the page stays usable, so a user can pick another item of the list while it is open. Escape (with focus in it) and the close button close it; a press beside it does not. Opening moves focus in. Closing gives it back only if it was still in the panel, to the last control used beside it. Where the query does not match it opens in its placement, for example as a sheet on a phone, and it switches form if the window crosses the query while it is open.
Without JavaScript the button opens the modal form at every width. In React, keep the component mounted and drive open from the chosen item: choosing another one changes the content, and the panel stays open.
---
import Sidepanel from '@subfloor/astro/Sidepanel.astro'
---
<div class="orders">
<ul>…<button command="show-modal" commandfor="order">Order 2</button>…</ul>
<!-- beside the list from 768px; a sheet below that, and without JavaScript -->
<Sidepanel id="order" title="Order" placement="bottom"
inlineAt="(min-width: 768px)">
…
</Sidepanel>
</div>
<style>
/* your layout gives it its place and height */
@media (min-width: 768px) {
.orders:has(> dialog[open]) { display: grid; grid-template-columns: 1fr 20rem; }
.orders > dialog { position: sticky; top: 0; height: 80dvh; }
}
</style>Customisation
.wide-sidepanel {
--sf-sidepanel-width: 32rem;
}
.short-sheet {
--sf-sheet-max-height: 60dvh;
--sf-sheet-bar-color: rebeccapurple;
}| Token | Default |
|---|---|
--sf-color-backdrop | rgb(9 9 11 / 50%) |
--sf-radius-overlay | 12px |
--sf-shadow-overlay | 0 20px 50px rgb(0 0 0 / 20%) |
--sf-overlay-gutter | var(--sf-space-4) |
--sf-sidepanel-width | 24rem |
--sf-sidepanel-inline-shadow | none |
--sf-sheet-max-height | 90dvh |
--sf-sheet-bar-width | 44px |
--sf-sheet-bar-height | 5px |
--sf-sheet-bar-offset | var(--sf-space-2) |
--sf-sheet-bar-color | var(--sf-field-border-color) |
--sf-button-spin-duration | 800ms |
--sf-duration-enter | 200ms |
--sf-duration-exit | 150ms |
--sf-ease-enter | cubic-bezier(0.2, 0.8, 0.2, 1) |
--sf-ease-exit | cubic-bezier(0.4, 0, 1, 1) |
Background
Content 1. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 2. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 3. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 4. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 5. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 6. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 7. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 8. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 9. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 10. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 11. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 12. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.