Mediquo documentation home

Drawer

A bottom sheet the patient drags down to close, for help or options on a phone.

mq-drawer is a bottom sheet that moves like Vaul: it slides up from the bottom edge, follows the finger when dragged down, and closes when let go far enough or flicked. It is built like Dialog, on the native <dialog>, so it has the same events, slots and keyboard behaviour. Use the dialog on desktop and the drawer on phones when a panel is long or the patient will want to swipe it away; the videocall's "Ayuda con la llamada" does exactly that.

Install

// Custom element — the import registers <mq-drawer>
import "@mediquo/ui/components/drawer";
// React
import { Drawer } from "@mediquo/ui/react/drawer";

Usage

The owner holds open and follows mq-close, which fires when the user drags it down, flicks it, taps outside, presses Escape or uses the close button. It is cancelable: preventDefault() keeps it open, and a drag springs back. onopenchange (event.open === false) follows once it really closes.

html`<mq-drawer
  .open=${this.open}
  .closeLabel=${msg("Cerrar")}
  @mq-close=${() => (this.open = false)}
>
  <h2 slot="heading">Ayuda con la llamada</h2>
  …
  <mq-button slot="footer" variant="primary">Hecho</mq-button>
</mq-drawer>`;
SlotWhat goes in it
headingThe title, next to the close button. Names the drawer.
(default)The body. It scrolls inside the sheet when it is long.
footerThe actions, end-aligned under a separator. Stays put.

Gestures

The numbers are Vaul's:

  • Open and close: transform with cubic-bezier(0.32, 0.72, 0, 1) over 500ms; the overlay fades with it. Closing slides out from wherever the sheet is, mid-drag included.
  • Drag down: the handle, the header or the content. The sheet follows the pointer 1:1 with no transition, and the overlay fades with the share of the height dragged.
  • Let go: it closes past 25% of its height, or on a flick faster than 0.4px/ms over the whole gesture; otherwise it springs back with the same curve.
  • Pull up: past its top the sheet gives a little, logarithmically (8 × (ln(d + 1) − 2): nothing for the first few pixels, about 21px at 100px), and springs back.
  • Scroll first: content scrolled down scrolls back up before the sheet moves; once at its top, the next drag moves the sheet. Momentum that has just reached the top (100ms) does not turn into a drag.
  • Left alone: a tap on a button inside, a drag that starts on a field (input, textarea, select, editable text), a mostly sideways drag, a press on the scrollbar, and a drag while text is selected. A drag that started on a button does not click it.

It uses pointer events with pointer capture, so a mouse drags it too, and touch-action: none on the sheet with native panning only in its scroll area.

Try the playground with long content on: scroll the text, then drag down.

Accessibility

  • It opens with showModal(): the page behind is inert, it sits in the top layer above everything, and focus moves to its first control. Tab wraps inside it. Escape closes it, and closing hands focus back to what opened it.
  • The heading names it (aria-labelledby); with no heading, pass label.
  • The close button is there for whoever cannot drag. It is named by close-label (default "Close"): pass it translated.
  • The handle is decoration (aria-hidden); every gesture has a key or a button.
  • When the content overflows, the scroll area takes keyboard focus (role="region", named by the heading).
  • The page scroll is locked without shifting the layout, shared with any open dialog.
  • Under prefers-reduced-motion: reduce it fades in and out where it is, with no slide; a drag still follows the finger.

Mobile and desktop

It spans the full width, up to --drawer-max-height (85dvh) tall, and keeps the bottom safe area (--mq-safe-bottom, else env(safe-area-inset-bottom)) clear. It does not switch to a centred dialog on wide screens: render mq-dialog there instead, as the help panel does from 768px.

Styling

The --drawer-* tokens are exported from @mediquo/ui/tokens (as components.drawer) and defined in tokens.css; the component falls back to the same values without the stylesheet.

mq-drawer {
  --drawer-underlay: rgb(0 0 0 / 0.5);
  --drawer-underlay-blur: 4px;
  --drawer-radius: 0.5rem;
  --drawer-max-height: 85dvh;
  --drawer-header-height: 3.75rem;
  --drawer-padding-inline: 1rem;
  --drawer-padding-block: 1.25rem;
  --drawer-actions-gap: 0.625rem;
  --drawer-transition-duration: 500ms;
  --drawer-easing: cubic-bezier(0.32, 0.72, 0, 1);
}

part is exposed for overlay, panel (the sheet), handle, header, heading, close, scroll, body and footer.

Not included

Vaul's snap points, its background scale effect (shouldScaleBackground: it would have to transform the host page, which a web component cannot do safely), nested drawers and the other directions. It is a bottom sheet only.