Skip to content

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

Installation

bash
npx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
yarn dlx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
bunx @galaxy-stack/nebula-cli@latest add alert-dialog
bash
# If you have installed galaxy-design globally
galaxy-design add alert-dialog

Usage

React

tsx
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from "@/components/ui/alert-dialog"

export default function App() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="destructive">Delete Account</Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogTitle>Are you sure?</AlertDialogTitle>
        <AlertDialogDescription>
          This action cannot be undone.
        </AlertDialogDescription>
        <AlertDialogCancel>Cancel</AlertDialogCancel>
        <AlertDialogAction>Delete</AlertDialogAction>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Vue

vue
<script setup lang="ts">
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui/alert-dialog'
</script>

<template>
  <AlertDialog>
    <AlertDialogTrigger asChild>
      <Button variant="destructive">Delete Account</Button>
    </AlertDialogTrigger>
    <AlertDialogContent>
      <AlertDialogTitle>Are you sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone.
      </AlertDialogDescription>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Delete</AlertDialogAction>
    </AlertDialogContent>
  </AlertDialog>
</template>

Angular

typescript
import { Component } from '@angular/core';
import { AlertDialogComponent } from '@/components/ui/alert-dialog';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [AlertDialogComponent],
  template: `
    <ui-alert-dialog [open]="isOpen" (openChange)="isOpen = $event">
      <ui-alert-dialog-trigger>
        <button variant="destructive">Delete Account</button>
      </ui-alert-dialog-trigger>
      <ui-alert-dialog-content>
        <ui-alert-dialog-title>Are you sure?</ui-alert-dialog-title>
        <ui-alert-dialog-description>
          This action cannot be undone.
        </ui-alert-dialog-description>
        <button (click)="isOpen = false">Cancel</button>
        <button (click)="handleDelete()">Delete</button>
      </ui-alert-dialog-content>
    </ui-alert-dialog>
  `
})
export class AppComponent {
  isOpen = false;

  handleDelete() {
    // Handle delete action
    this.isOpen = false;
  }
}

React Native

tsx
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui/alert-dialog'
import { Button, ButtonText } from '@/components/ui/button'

export default function App() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="destructive">
          <ButtonText>Delete Account</ButtonText>
        </Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogTitle>Are you sure?</AlertDialogTitle>
        <AlertDialogDescription>
          This action cannot be undone.
        </AlertDialogDescription>
        <AlertDialogCancel>
          <ButtonText>Cancel</ButtonText>
        </AlertDialogCancel>
        <AlertDialogAction>
          <ButtonText>Delete</ButtonText>
        </AlertDialogAction>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Flutter

dart
import 'package:flutter/material.dart';
import 'package:galaxy_design/galaxy_alert_dialog.dart';

class AlertDialogExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GalaxyButton(
      variant: GalaxyButtonVariant.destructive,
      onPressed: () {
        GalaxyAlertDialog.show(
          context: context,
          title: 'Are you sure?',
          description: 'This action cannot be undone.',
          cancelText: 'Cancel',
          confirmText: 'Delete',
          onConfirm: () {
            // Handle delete action
          },
        );
      },
      child: const Text('Delete Account'),
    );
  }
}

API Reference

Props

PropTypeDefaultDescriptionFrameworks
openboolean-Controlled open stateReact, Vue, Angular
defaultOpenbooleanfalseInitial open state for uncontrolled usageReact, Vue, Angular
onOpenChange / update:open(open: boolean) => void-Called when the open state changesReact (onOpenChange), Vue (update:open), Angular
titlestring-Optional title textFlutter only
descriptionstring-Optional description textFlutter only
cancelTextstring'Cancel'Cancel button textFlutter only
confirmTextstring'Confirm'Confirm button textFlutter only
variant'default' | 'destructive''default'Visual style variantFlutter only
paddingEdgeInsetsGeometry-Padding inside the alert containerFlutter only

Sub-components

AlertDialogTrigger

PropTypeDefaultDescriptionFrameworks
asChildbooleanfalseRender the trigger as a child elementReact, Vue
asAsTag | Component'button'Element or component to renderVue only

AlertDialogContent

PropTypeDefaultDescriptionFrameworks
forceMountboolean-Force-mount the content even when closedReact, Vue
className / classstring-CSS class namesReact (className), Vue (class)
onOpenAutoFocus(event: Event) => void-Called when focus moves into the alert dialog after openingReact only
onCloseAutoFocus(event: Event) => void-Called when focus returns after closingReact only

Vue

vue
<script setup lang="ts">
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui'
</script>

<template>
  <AlertDialog>
    <AlertDialogTrigger>Delete Account</AlertDialogTrigger>
    <AlertDialogContent>
      <AlertDialogTitle>Are you sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone.
      </AlertDialogDescription>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Delete</AlertDialogAction>
    </AlertDialogContent>
  </AlertDialog>
</template>

React

tsx
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel
} from '@/components/ui'

export default function AlertDialogDemo() {
  return (
    <AlertDialog>
      <AlertDialogTrigger>Delete Account</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogTitle>Are you sure?</AlertDialogTitle>
        <AlertDialogDescription>
          This action cannot be undone.
        </AlertDialogDescription>
        <AlertDialogCancel>Cancel</AlertDialogCancel>
        <AlertDialogAction>Delete</AlertDialogAction>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Angular

typescript
import { Component } from '@angular/core';
import { AlertDialogComponent } from '@/components/ui';

@Component({
  selector: 'app-alert-dialog-demo',
  standalone: true,
  imports: [AlertDialogComponent],
  template: `
    <ui-alert-dialog [isOpen]="isOpen" (openChange)="isOpen = $event">
      <h2>Are you sure?</h2>
      <p>This action cannot be undone.</p>
      <button (click)="isOpen = false">Cancel</button>
      <button (click)="handleDelete()">Delete</button>
    </ui-alert-dialog>
  `
})
export class AlertDialogDemoComponent {
  isOpen = false;

  handleDelete() {
    this.isOpen = false;
    // Handle delete
  }
}

Accessibility

  • Keyboard Navigation: [TODO]
  • Screen Reader: [TODO]
  • Focus Management: [TODO]
  • WCAG Compliance: WCAG 2.1 Level AA compliant

Author

Bùi Trọng Hiếu (kevinbui)

License

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Released under the MIT License.