Vue playground

Nova v3.37.0

Preview

Vue

nv-drawer guide

Building accessible slide-out drawers with a header and footer.

← nv-drawer

Drawer Component Guide for Native Web Components

Introduction

The Drawer components (nv-drawer, nv-drawerheader, and nv-drawerfooter) are native Web Components built with Stencil.js that provide accessible slide-out panels. As standard Web Components, they work seamlessly in any modern browser and can be used with or without JavaScript frameworks.

Key Features:

  • Accessible slide-out panels with proper ARIA attributes and focus management
  • Slide from left or right side
  • Multiple size options (sm, md, lg, full)
  • Swipe gestures support for mobile devices
  • Backdrop click and escape key handling
  • Form integration support
  • Controlled and uncontrolled modes
  • Framework agnostic
  • Standards compliant Web Component

Installation

Install Nova's Web Components via npm:

bashnpm install @nova-design-system/native

Then import the components in your JavaScript:

javascriptimport '@nova-design-system/native/dist/nova-components/nova-components.css';
import '@nova-design-system/native/dist/nova-components/nova-components.js';

Basic Usage

Simple Drawer

The most basic drawer implementation uses nv-drawer with a trigger button:

html<nv-drawer>
  <button slot="trigger">Open Drawer</button>
  <p>This is the drawer content.</p>
</nv-drawer>

Drawer with Header and Footer

Use nv-drawerheader and nv-drawerfooter for structured drawers:

html<nv-drawer side="right">
  <button slot="trigger">Open Drawer</button>
  
  <nv-drawerheader heading="Settings" subheading="Manage your preferences">
  </nv-drawerheader>
  
  <p>Drawer body content goes here.</p>
  
  <nv-drawerfooter 
    primary-label="Save" 
    cancel-label="Cancel">
  </nv-drawerfooter>
</nv-drawer>

Left Side Drawer

Slide the drawer from the left side:

html<nv-drawer side="left">
  <button slot="trigger">Menu</button>
  
  <nv-drawerheader heading="Navigation"></nv-drawerheader>
  
  <nav>
    <a href="/dashboard">Dashboard</a>
    <a href="/profile">Profile</a>
    <a href="/settings">Settings</a>
  </nav>
</nv-drawer>

Advanced Usage

Different Drawer Sizes

Control the drawer width with the size property:

html<!-- Small drawer (~320px) -->
<nv-drawer size="sm">
  <button slot="trigger">Quick Actions</button>
  <p>Compact drawer content.</p>
</nv-drawer>

<!-- Medium drawer (~400px) - Default -->
<nv-drawer size="md">
  <button slot="trigger">Open Drawer</button>
  <p>Standard drawer content.</p>
</nv-drawer>

<!-- Large drawer (~600px) -->
<nv-drawer size="lg">
  <button slot="trigger">Detailed View</button>
  <p>Wide drawer with more content space.</p>
</nv-drawer>

<!-- Full width drawer -->
<nv-drawer size="full">
  <button slot="trigger">Full Panel</button>
  <p>Full-width drawer for extensive content.</p>
</nv-drawer>

Custom Width

Override the size with a custom width:

html<nv-drawer width="500px">
  <button slot="trigger">Custom Width</button>
  <p>This drawer has a custom 500px width.</p>
</nv-drawer>

Swipe to Open/Close

Enable swipe gestures on touch devices:

html<nv-drawer side="right" swipe-to-open>
  <button slot="trigger">Open Drawer</button>
  
  <nv-drawerheader heading="Swipeable Drawer"></nv-drawerheader>
  
  <p>You can swipe from the right edge to open this drawer on touch devices.</p>
  <p>Swipe right to close it.</p>
</nv-drawer>

Controlled Drawer

Control the drawer's open state programmatically:

html<nv-drawer id="myDrawer" controlled open="false">
  <button slot="trigger">Open Drawer</button>
  <nv-drawerheader heading="Controlled Drawer"></nv-drawerheader>
  <p>This drawer is controlled via JavaScript.</p>
  <nv-drawerfooter></nv-drawerfooter>
</nv-drawer>

<script>
  const drawer = document.getElementById('myDrawer');
  const openButton = document.getElementById('openBtn');
  
  openButton.addEventListener('click', () => {
    drawer.open = true;
  });
  
  drawer.addEventListener('nvClose', () => {
    console.log('Drawer closed');
  });
</script>

Drawer with Form

Integrate forms within drawers:

html<nv-drawer size="lg">
  <button slot="trigger">Edit Profile</button>
  
  <nv-drawerheader 
    heading="Edit Profile" 
    subheading="Update your information">
  </nv-drawerheader>
  
  <form>
    <nv-fieldtext label="Full Name" required></nv-fieldtext>
    <nv-fieldtext label="Email" type="email" required></nv-fieldtext>
    <nv-fieldtext label="Phone"></nv-fieldtext>
    <nv-fieldtextarea label="Bio"></nv-fieldtextarea>
  </form>
  
  <nv-drawerfooter 
    primary-label="Save Changes" 
    primary-type="submit">
  </nv-drawerfooter>
</nv-drawer>

Click Outside to Close

Allow closing the drawer by clicking the backdrop:

html<nv-drawer click-outside>
  <button slot="trigger">Open Drawer</button>
  
  <nv-drawerheader heading="Click Outside"></nv-drawerheader>
  
  <p>Click the backdrop to close this drawer.</p>
  
  <nv-drawerfooter></nv-drawerfooter>
</nv-drawer>

Undismissable Drawer

Prevent users from closing the drawer except through explicit actions:

html<nv-drawer undismissable>
  <button slot="trigger">Important Action</button>
  
  <nv-drawerheader heading="Complete Required Steps"></nv-drawerheader>
  
  <p>Please complete all required fields before closing.</p>
  
  <nv-drawerfooter 
    primary-label="Complete" 
    undismissable>
  </nv-drawerfooter>
</nv-drawer>

Component Composition

The drawer system consists of three components that work together:

nv-drawer (Container)

The parent container that manages the drawer behavior and visibility.

Properties:

  • open: boolean - Controls drawer visibility
  • side: "left" | "right" - Side from which drawer appears (default: right)
  • size: "sm" | "md" | "lg" | "full" - Drawer size preset
  • width: string - Custom width (overrides size)
  • undismissable: boolean - Prevents closing via backdrop/escape
  • click-outside: boolean - Allows closing by clicking backdrop
  • controlled: boolean - Manual control via open prop/methods
  • autofocus: boolean - Auto-focus first element on open
  • swipe-to-open: boolean - Enable swipe gestures

Events:

  • nvOpen - Fired when drawer opens
  • nvClose - Fired when drawer closes

Methods:

  • show() - Opens the drawer
  • hide() - Closes the drawer

Slots:

  • trigger - Trigger button/element
  • header - Header content
  • default - Body content
  • footer - Footer content

nv-drawerheader

Provides a structured header for the drawer.

Properties:

  • heading: string - Main heading text
  • subheading: string - Optional subtitle text

Slots:

  • default - Custom header content (overrides heading/subheading)

nv-drawerfooter

Provides action buttons in the footer.

Properties:

  • primary-label: string - Primary button text
  • primary-type: string - Primary button type (button/submit)
  • primary-icon: string - Icon for primary button
  • cancel-label: string - Cancel button text
  • disabled: boolean - Disables primary button
  • undismissable: boolean - Hides cancel button

Events:

  • nvPrimary - Fired when primary button is clicked
  • nvCancel - Fired when cancel button is clicked

Slots:

  • default - Custom footer content (overrides default buttons)

Complete Example

html<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Nova Drawer Example</title>
  <script type="module">
    import '@nova-design-system/native/dist/nova-components/nova-components.css';
    import '@nova-design-system/native/dist/nova-components/nova-components.js';
  </script>
</head>
<body>
  <main class="container">
    <!-- Navigation Drawer -->
    <nv-drawer id="navDrawer" side="left" size="sm">
      <nv-button slot="trigger">
        <nv-icon name="menu"></nv-icon>
        Menu
      </nv-button>
      
      <nv-drawerheader heading="Navigation"></nv-drawerheader>
      
      <nav>
        <a href="/dashboard">
          <nv-icon name="home"></nv-icon>
          Dashboard
        </a>
        <a href="/profile">
          <nv-icon name="user"></nv-icon>
          Profile
        </a>
        <a href="/settings">
          <nv-icon name="settings"></nv-icon>
          Settings
        </a>
      </nav>
    </nv-drawer>

    <!-- Settings Drawer -->
    <nv-drawer id="settingsDrawer" side="right" size="lg">
      <nv-button slot="trigger">Settings</nv-button>
      
      <nv-drawerheader 
        heading="Account Settings" 
        subheading="Manage your preferences">
      </nv-drawerheader>
      
      <form id="settingsForm">
        <nv-fieldtext label="Display Name" value="John Doe"></nv-fieldtext>
        <nv-fieldtext label="Email" type="email" value="john@example.com"></nv-fieldtext>
        <nv-toggle label="Email Notifications"></nv-toggle>
        <nv-toggle label="Dark Mode"></nv-toggle>
      </form>
      
      <nv-drawerfooter 
        primary-label="Save Changes" 
        cancel-label="Cancel"
        primary-type="submit">
      </nv-drawerfooter>
    </nv-drawer>
  </main>

  <script>
    const settingsDrawer = document.getElementById('settingsDrawer');
    
    settingsDrawer.addEventListener('nvPrimary', () => {
      console.log('Settings saved');
      settingsDrawer.hide();
    });
    
    settingsDrawer.addEventListener('nvCancel', () => {
      console.log('Settings cancelled');
    });
  </script>
</body>
</html>

Accessibility Best Practices

  1. Always provide meaningful heading text:

    html<nv-drawerheader heading="Account Settings"></nv-drawerheader>
    
  2. Use descriptive button labels:

    html<nv-drawerfooter 
      primary-label="Save Changes" 
      cancel-label="Discard">
    </nv-drawerfooter>
    
  3. Focus management is handled automatically - focus moves to the drawer when opened and returns to the trigger when closed

  4. Keyboard navigation:

    • Escape closes the drawer (unless undismissable)
    • Tab cycles through focusable elements
    • Enter or Space on trigger opens the drawer
  5. Choose appropriate side based on reading direction and UI layout:

    • Left side: Navigation menus, filters
    • Right side: Settings, detailed views, forms
  6. Use undismissable sparingly - only for critical actions that require completion

Common Patterns

Navigation Drawer

html<nv-drawer side="left" size="sm" click-outside>
  <nv-iconbutton slot="trigger" name="menu"></nv-iconbutton>
  
  <nv-drawerheader heading="Menu"></nv-drawerheader>
  
  <nav>
    <a href="/dashboard">Dashboard</a>
    <a href="/projects">Projects</a>
    <a href="/team">Team</a>
    <a href="/settings">Settings</a>
  </nav>
</nv-drawer>

Filter Drawer

html<nv-drawer side="left" size="md">
  <nv-button slot="trigger">Filters</nv-button>
  
  <nv-drawerheader heading="Filter Results"></nv-drawerheader>
  
  <form>
    <nv-fieldselect label="Category">
      <option>All</option>
      <option>Electronics</option>
      <option>Clothing</option>
    </nv-fieldselect>
    
    <nv-fieldslider label="Price Range" min="0" max="1000"></nv-fieldslider>
    
    <nv-fieldcheckbox label="In Stock Only"></nv-fieldcheckbox>
  </form>
  
  <nv-drawerfooter 
    primary-label="Apply Filters" 
    cancel-label="Clear">
  </nv-drawerfooter>
</nv-drawer>

Detail View Drawer

html<nv-drawer side="right" size="lg">
  <nv-button slot="trigger">View Details</nv-button>
  
  <nv-drawerheader 
    heading="Order #12345" 
    subheading="Placed on Jan 15, 2026">
  </nv-drawerheader>
  
  <div class="order-details">
    <h3>Items</h3>
    <ul>
      <li>Product A - $29.99</li>
      <li>Product B - $49.99</li>
    </ul>
    
    <h3>Shipping</h3>
    <p>123 Main St, City, State 12345</p>
    
    <h3>Total</h3>
    <p>$79.98</p>
  </div>
  
  <nv-drawerfooter undismissable>
    <nv-button>Track Order</nv-button>
  </nv-drawerfooter>
</nv-drawer>

Framework Integration

React

jsximport '@nova-design-system/native/dist/nova-components/nova-components.css';
import { NvDrawer, NvDrawerheader, NvDrawerfooter, NvButton } from '@nova-design-system/react';

function SettingsDrawer() {
  const handleSave = () => {
    console.log('Settings saved');
  };

  return (
    <NvDrawer side="right" size="lg">
      <NvButton slot="trigger">Settings</NvButton>
      <NvDrawerheader heading="Settings" />
      <form>
        <input type="text" placeholder="Name" />
      </form>
      <NvDrawerfooter 
        primaryLabel="Save"
        onNvPrimary={handleSave}
      />
    </NvDrawer>
  );
}

Vue

vue<template>
  <nv-drawer side="left" size="sm">
    <nv-button slot="trigger">Menu</nv-button>
    <nv-drawerheader heading="Navigation" />
    <nav>
      <a href="/home">Home</a>
      <a href="/about">About</a>
    </nav>
  </nv-drawer>
</template>

<script setup>
import '@nova-design-system/native/dist/nova-components/nova-components.css';
import '@nova-design-system/native/dist/nova-components/nova-components.js';
</script>

Angular

typescriptimport { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@nova-design-system/native/dist/nova-components/nova-components.css';
import '@nova-design-system/native/dist/nova-components/nova-components.js';

@Component({
  selector: 'app-drawer',
  template: `
    <nv-drawer side="right">
      <nv-button slot="trigger">Open Drawer</nv-button>
      <nv-drawerheader heading="Angular Drawer"></nv-drawerheader>
      <p>Drawer content</p>
      <nv-drawerfooter 
        primaryLabel="Confirm"
        (nvPrimary)="handleConfirm()">
      </nv-drawerfooter>
    </nv-drawer>
  `,
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class DrawerComponent {
  handleConfirm() {
    console.log('Confirmed');
  }
}

Troubleshooting

Drawer not opening

  • Ensure the trigger element is properly slotted: <button slot="trigger">...</button>
  • Check if controlled mode is enabled - you may need to set open property manually
  • Verify that JavaScript is loaded and components are defined

Drawer appearing on wrong side

  • Check the side property - it should be either "left" or "right"
  • Default is "right" if not specified

Swipe gestures not working

  • Ensure swipe-to-open is set to true
  • Swipe gestures only work on touch devices
  • Swipe from the edge (within 20px) for opening

Custom width not applied

  • The width property overrides size
  • Ensure you're using valid CSS units: "500px", "50%", etc.

API Reference

For detailed API documentation including all properties, events, methods, and slots, see the component documentation tabs:

  • nv-drawer - Main drawer container
  • nv-drawerheader - Drawer header component
  • nv-drawerfooter - Drawer footer component