Offcanvas
Extend the Sidenav into a full offcanvas panel that slides in from any edge. Uses the existing useSidenav API with positional modifiers.
VdOffcanvas Component
Left (Default)
Right
Top
Bottom
Using data-vd-position
You can set the slide direction entirely through the data-vd-position attribute instead of adding directional CSS classes. The JS reads this attribute at init time and applies the correct transform.
API Reference
Wiring
import { ref } from 'vue';
import { useSidenav } from "@vanduo-oss/vd3";
const root = ref<HTMLElement | null>(null);
useSidenav(root); // wires [data-sidenav-toggle] triggers; cleanup on unmountCSS Classes
| Class | Description | Type |
|---|---|---|
.vd-offcanvas | Base offcanvas panel — extends .vd-sidenav behaviour | Base |
.vd-offcanvas-top | Slide from the top edge (full-width) | Modifier |
.vd-offcanvas-bottom | Slide from the bottom edge (full-width) | Modifier |
.vd-offcanvas-right | Slide from the right edge | Modifier |
.vd-sidenav-top | Legacy alias for .vd-offcanvas-top | Modifier |
.vd-sidenav-bottom | Legacy alias for .vd-offcanvas-bottom | Modifier |
.is-open | Applied when the panel is visible | State |
Data Attributes
| Attribute | Description | Default |
|---|---|---|
data-vd-position | Set slide direction: top, right, bottom, or left | left |
data-sidenav-toggle | Place on trigger element — value is the selector for the offcanvas (e.g. "#my-panel") | — |
VdOffcanvas Component API
| Prop / Event / Slot | Description |
|---|---|
v-model (modelValue) | boolean — controls open/closed offcanvas visibility. |
:placement | "right" (default) | "left" | "top" | "bottom". |
:title | string — header title and accessible dialog aria-label. |
:closeOnBackdrop | boolean (default true) — close when clicking the overlay backdrop. |
:closeOnEsc | boolean (default true) — close when pressing Escape. |
:animated | boolean (default true) — smooth sliding transition using Fibonacci timing and golden easing. |
@close | Emitted when the offcanvas panel closes. |
#header / default | Named #header slot for custom header content and default slot for panel body. |
Composable API
| Symbol | Description |
|---|---|
useSidenav(root) | Composable — wires every [data-sidenav-toggle] trigger inside the root ref (overlay, close button, ESC, scroll-lock). Call once in setup(). |
(automatic cleanup) | Listeners and the body overlay are removed on component unmount. |
Events
| Event | Description | Detail |
|---|---|---|
sidenav:open | Fired on the offcanvas element after it becomes visible | { position } |
sidenav:close | Fired on the offcanvas element after it is hidden | { position } |
Accessibility
VdOffcanvasrendersrole="dialog"witharia-modal="true", traps focus inside the panel while open, and returns focus to the previously focused element on closeuseSidenavpanels getrole="navigation"and a syncedaria-hidden; they do not trap focus — useVdOffcanvaswhen the panel needs modal dialog semantics- Close button includes
aria-label="Close"for assistive technology - Pressing Escape closes the offcanvas panel
- Overlay backdrop blocks interaction with the page beneath
[data-sidenav-toggle]triggers receivearia-controlsand anaria-expandedthat tracks the open/closed state