Blazor playground

Nova v3.37.0

Preview

Blazor

nv-dialog guide

Building accessible modal dialogs with a header and footer.

← nv-dialog

Dialog Component Guide for Native Web Components

Introduction

The Dialog components (nv-dialog, nv-dialogheader, and nv-dialogfooter) are native Web Components built with Stencil.js that provide accessible modal dialogs. As standard Web Components, they work seamlessly in any modern browser and can be used with or without JavaScript frameworks.

Key Features:

  • Accessible modal dialogs with proper ARIA attributes and focus management
  • Customizable header and footer components
  • 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 Dialog

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

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

Dialog with Header and Footer

Use nv-dialogheader and nv-dialogfooter for structured dialogs:

html<nv-dialog>
  <button slot="trigger">Open Dialog</button>
  
  <nv-dialogheader heading="Dialog Title" subheading="Optional subtitle">
  </nv-dialogheader>
  
  <p>Dialog body content goes here.</p>
  
  <nv-dialogfooter 
    primary-label="Confirm" 
    cancel-label="Cancel">
  </nv-dialogfooter>
</nv-dialog>

Advanced Usage

Controlled Dialog

Control the dialog's open state programmatically:

html<nv-dialog id="myDialog" controlled open="false">
  <button slot="trigger">Open Dialog</button>
  <nv-dialogheader heading="Controlled Dialog"></nv-dialogheader>
  <p>This dialog is controlled via JavaScript.</p>
  <nv-dialogfooter></nv-dialogfooter>
</nv-dialog>

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

Dialog with Custom Footer

Create custom footer actions using the slot:

html<nv-dialog>
  <button slot="trigger">Open Dialog</button>
  
  <nv-dialogheader heading="Custom Footer"></nv-dialogheader>
  
  <p>Dialog content here.</p>
  
  <nv-dialogfooter>
    <nv-button variant="text">Later</nv-button>
    <nv-button variant="secondary">Save Draft</nv-button>
    <nv-button variant="primary">Publish</nv-button>
  </nv-dialogfooter>
</nv-dialog>

Undismissable Dialog

Prevent users from closing the dialog except through explicit actions:

html<nv-dialog undismissable>
  <button slot="trigger">Open Dialog</button>
  
  <nv-dialogheader heading="Important Action"></nv-dialogheader>
  
  <p>This dialog cannot be closed by clicking outside or pressing Escape.</p>
  
  <nv-dialogfooter 
    primary-label="I Understand"
    undismissable>
  </nv-dialogfooter>
</nv-dialog>

Dialog with Form

Integrate forms within dialogs:

html<nv-dialog>
  <button slot="trigger">Add User</button>
  
  <nv-dialogheader 
    heading="Add New User" 
    subheading="Fill in the user details">
  </nv-dialogheader>
  
  <form>
    <nv-fieldtext label="Name" required></nv-fieldtext>
    <nv-fieldtext label="Email" type="email" required></nv-fieldtext>
    <nv-fieldselect label="Role" required>
      <option value="user">User</option>
      <option value="admin">Admin</option>
    </nv-fieldselect>
  </form>
  
  <nv-dialogfooter 
    primary-label="Add User" 
    primary-type="submit">
  </nv-dialogfooter>
</nv-dialog>

Click Outside to Close

Allow closing the dialog by clicking the backdrop:

html<nv-dialog click-outside>
  <button slot="trigger">Open Dialog</button>
  
  <nv-dialogheader heading="Click Outside"></nv-dialogheader>
  
  <p>Click the backdrop to close this dialog.</p>
  
  <nv-dialogfooter></nv-dialogfooter>
</nv-dialog>

Component Composition

The dialog system consists of three components that work together:

nv-dialog (Container)

The parent container that manages the dialog behavior and visibility.

Properties:

  • open: boolean - Controls dialog visibility
  • undismissable: boolean - Prevents closing via backdrop/escape
  • click-outside: boolean - Allows closing by clicking backdrop
  • controlled: boolean - Manual control via open prop/methods
  • size: "sm" | "md" | "lg" | "xl" | "full" - Dialog size

Events:

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

Methods:

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

Slots:

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

nv-dialogheader

Provides a structured header for the dialog.

Properties:

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

Slots:

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

nv-dialogfooter

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 Dialog 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">
    <!-- Confirmation Dialog -->
    <nv-dialog id="confirmDialog">
      <nv-button slot="trigger">Delete Item</nv-button>
      
      <nv-dialogheader 
        heading="Confirm Deletion" 
        subheading="This action cannot be undone">
      </nv-dialogheader>
      
      <p>Are you sure you want to delete this item? This will permanently remove it from your account.</p>
      
      <nv-dialogfooter 
        primary-label="Delete" 
        cancel-label="Cancel"
        leading-icon="trash">
      </nv-dialogfooter>
    </nv-dialog>
  </main>

  <script>
    const dialog = document.getElementById('confirmDialog');
    
    dialog.addEventListener('nvPrimary', () => {
      console.log('Item deleted');
      dialog.hide();
    });
    
    dialog.addEventListener('nvCancel', () => {
      console.log('Deletion cancelled');
    });
  </script>
</body>
</html>

Accessibility Best Practices

  1. Always provide meaningful heading text:

    html<nv-dialogheader heading="Delete Confirmation"></nv-dialogheader>
    
  2. Use descriptive button labels:

    html<nv-dialogfooter 
      primary-label="Confirm Delete" 
      cancel-label="Keep Item">
    </nv-dialogfooter>
    
  3. Focus management is handled automatically - focus moves to the dialog when opened and returns to the trigger when closed

  4. Keyboard navigation:

    • Escape closes the dialog (unless undismissable)
    • Tab cycles through focusable elements
    • Enter or Space on trigger opens the dialog
  5. Use undismissable sparingly - only for critical actions that require user acknowledgment

Common Patterns

Confirmation Dialog

html<nv-dialog>
  <nv-button slot="trigger" variant="danger">Delete Account</nv-button>
  
  <nv-dialogheader 
    heading="Delete Account" 
    subheading="This action is permanent">
  </nv-dialogheader>
  
  <p>Are you sure you want to delete your account? All your data will be permanently removed.</p>
  
  <nv-dialogfooter 
    primary-label="Delete Account" 
    cancel-label="Keep Account">
  </nv-dialogfooter>
</nv-dialog>

Form Dialog

html<nv-dialog size="lg">
  <nv-button slot="trigger">Create Project</nv-button>
  
  <nv-dialogheader heading="New Project"></nv-dialogheader>
  
  <form id="projectForm">
    <nv-fieldtext label="Project Name" required></nv-fieldtext>
    <nv-fieldtextarea label="Description"></nv-fieldtextarea>
    <nv-fielddate label="Start Date"></nv-fielddate>
  </form>
  
  <nv-dialogfooter 
    primary-label="Create" 
    primary-type="submit">
  </nv-dialogfooter>
</nv-dialog>

Information Dialog

html<nv-dialog click-outside>
  <nv-button slot="trigger" variant="text">About</nv-button>
  
  <nv-dialogheader heading="About This App"></nv-dialogheader>
  
  <p>Version 1.0.0</p>
  <p>Built with Nova Design System</p>
  
  <nv-dialogfooter undismissable>
    <nv-button>Close</nv-button>
  </nv-dialogfooter>
</nv-dialog>

Framework Integration

React

jsximport '@nova-design-system/native/dist/nova-components/nova-components.css';
import { NvDialog, NvDialogheader, NvDialogfooter, NvButton } from '@nova-design-system/react';

function ConfirmDialog() {
  const handlePrimary = () => {
    console.log('Confirmed');
  };

  return (
    <NvDialog>
      <NvButton slot="trigger">Confirm Action</NvButton>
      <NvDialogheader heading="Confirmation" />
      <p>Are you sure?</p>
      <NvDialogfooter 
        primaryLabel="Confirm"
        onNvPrimary={handlePrimary}
      />
    </NvDialog>
  );
}

Vue

vue<template>
  <nv-dialog>
    <nv-button slot="trigger">Open Dialog</nv-button>
    <nv-dialogheader heading="Vue Dialog" />
    <p>Dialog content</p>
    <nv-dialogfooter 
      primary-label="OK"
      @nvPrimary="handleConfirm"
    />
  </nv-dialog>
</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';

const handleConfirm = () => {
  console.log('Confirmed');
};
</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-dialog',
  template: `
    <nv-dialog>
      <nv-button slot="trigger">Open Dialog</nv-button>
      <nv-dialogheader heading="Angular Dialog"></nv-dialogheader>
      <p>Dialog content</p>
      <nv-dialogfooter 
        primaryLabel="Confirm"
        (nvPrimary)="handleConfirm()">
      </nv-dialogfooter>
    </nv-dialog>
  `,
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class DialogComponent {
  handleConfirm() {
    console.log('Confirmed');
  }
}

Troubleshooting

Dialog 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

Focus not trapped in dialog

  • This is automatic behavior - if not working, check for JavaScript errors
  • Ensure focusable elements exist within the dialog

Form submission not working

  • Set primary-type="submit" on the dialogfooter
  • Wrap your form fields in a <form> element
  • Listen for the nvPrimary event to handle submission

API Reference

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

  • nv-dialog - Main dialog container
  • nv-dialogheader - Dialog header component
  • nv-dialogfooter - Dialog footer component