Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Modal

    Modal dialog built on the native dialog element, with focus trapping and a close button.

    Delete project?

    The project and all of its data will be deleted permanently.

    Delete project?

    The project and all of its data will be deleted permanently.

    Delete project?

    The project and all of its data will be deleted permanently.

    Delete project?

    The project and all of its data will be deleted permanently.

    Delete project?

    The project and all of its data will be deleted permanently.
    <x-markas.modal title="Delete project?">
        <x-slot:trigger>
            <x-markas.button variant="danger">Delete project</x-markas.button>
        </x-slot:trigger>
    
        The project and all of its data will be deleted permanently.
    
        <x-slot:footer>
            <x-markas.button variant="secondary" type="submit" value="cancel">Cancel</x-markas.button>
            <x-markas.button variant="danger" type="submit" value="delete">Delete</x-markas.button>
        </x-slot:footer>
    </x-markas.modal>
    import { Button } from "@/components/markas/Button";
    import { Modal } from "@/components/markas/Modal";
    
    export default function ModalExample() {
      return (
        <Modal
          title="Delete project?"
          trigger={<Button variant="danger">Delete project</Button>}
          footer={
            <>
              <Button variant="secondary" type="submit" value="cancel">
                Cancel
              </Button>
              <Button variant="danger" type="submit" value="delete">
                Delete
              </Button>
            </>
          }
        >
          The project and all of its data will be deleted permanently.
        </Modal>
      );
    }
    <script setup lang="ts">
    import Button from "@/components/markas/Button.vue";
    import Modal from "@/components/markas/Modal.vue";
    </script>
    
    <template>
      <Modal title="Delete project?">
        <template #trigger>
          <Button variant="danger">Delete project</Button>
        </template>
    
        The project and all of its data will be deleted permanently.
    
        <template #footer>
          <Button variant="secondary" type="submit" value="cancel">Cancel</Button>
          <Button variant="danger" type="submit" value="delete">Delete</Button>
        </template>
      </Modal>
    </template>
    <script lang="ts">
      import Button from "$lib/components/markas/Button.svelte";
      import Modal from "$lib/components/markas/Modal.svelte";
    </script>
    
    <Modal title="Delete project?">
      {#snippet trigger()}
        <Button variant="danger">Delete project</Button>
      {/snippet}
    
      The project and all of its data will be deleted permanently.
    
      {#snippet footer()}
        <Button variant="secondary" type="submit" value="cancel">Cancel</Button>
        <Button variant="danger" type="submit" value="delete">Delete</Button>
      {/snippet}
    </Modal>
    ---
    import Button from "@/components/markas/Button.astro";
    import Modal from "@/components/markas/Modal.astro";
    ---
    
    <Modal title="Delete project?">
      <Button slot="trigger" variant="danger">Delete project</Button>
    
      The project and all of its data will be deleted permanently.
    
      <Fragment slot="footer">
        <Button variant="secondary" type="submit" value="cancel">Cancel</Button>
        <Button variant="danger" type="submit" value="delete">Delete</Button>
      </Fragment>
    </Modal>
    import { Component } from "@angular/core";
    import { Button } from "./markas/button.component";
    import { Modal } from "./markas/modal.component";
    
    @Component({
      selector: "markas-example",
      imports: [Button, Modal],
      template: `
        <markas-modal title="Delete project?">
          <button markas-button trigger variant="danger">Delete project</button>
    
          The project and all of its data will be deleted permanently.
    
          <ng-container footer>
            <button markas-button variant="secondary" type="submit" value="cancel">
              Cancel
            </button>
            <button markas-button variant="danger" type="submit" value="delete">
              Delete
            </button>
          </ng-container>
        </markas-modal>
      `,
    })
    export default class ModalExample {}

    Examples

    Delete confirmation

    Delete 3 files?

    These files will be removed from the shared folder for everyone. You cannot undo this action.

    Delete 3 files?

    These files will be removed from the shared folder for everyone. You cannot undo this action.

    Delete 3 files?

    These files will be removed from the shared folder for everyone. You cannot undo this action.

    Delete 3 files?

    These files will be removed from the shared folder for everyone. You cannot undo this action.

    Delete 3 files?

    These files will be removed from the shared folder for everyone. You cannot undo this action.

    With form

    Invite a team member

    We will send a link to join the workspace.

    Invite a team member

    We will send a link to join the workspace.

    Invite a team member

    We will send a link to join the workspace.

    Invite a team member

    We will send a link to join the workspace.

    Invite a team member

    We will send a link to join the workspace.

    Single action

    What's new in version 2.4

    • Dark mode now follows your system setting.
    • Export reports to CSV from any table.
    • Search results load twice as fast.

    What's new in version 2.4

    • Dark mode now follows your system setting.
    • Export reports to CSV from any table.
    • Search results load twice as fast.

    What's new in version 2.4

    • Dark mode now follows your system setting.
    • Export reports to CSV from any table.
    • Search results load twice as fast.

    What's new in version 2.4

    • Dark mode now follows your system setting.
    • Export reports to CSV from any table.
    • Search results load twice as fast.

    What's new in version 2.4

    • Dark mode now follows your system setting.
    • Export reports to CSV from any table.
    • Search results load twice as fast.

    Icon trigger

    Share project

    Anyone with the link can view this project. Only members can edit it.

    Share project

    Anyone with the link can view this project. Only members can edit it.

    Share project

    Anyone with the link can view this project. Only members can edit it.

    Share project

    Anyone with the link can view this project. Only members can edit it.

    Share project

    Anyone with the link can view this project. Only members can edit it.

    Installation

    npx markasui@latest add modal

    Usage

    <x-markas.modal title="Delete project?">
        <x-slot:trigger>
            <x-markas.button variant="danger">Delete</x-markas.button>
        </x-slot:trigger>
    
        The project and all of its data will be deleted permanently.
    
        <x-slot:footer>
            <x-markas.button variant="secondary" type="submit" value="cancel">Cancel</x-markas.button>
            <x-markas.button variant="danger" type="submit" value="delete">Delete</x-markas.button>
        </x-slot:footer>
    </x-markas.modal>

    Needs Alpine.js. Livewire 3 and 4 already ship it.

    Livewire

    <x-markas.modal title="Edit profile" wire:model="showEdit">
        ...
    </x-markas.modal>

    wire:model binds the open state: set $showEdit = true in an action to open the dialog, false to close it. Closing with Escape, the close button, or the backdrop sets it back to false. The dialog keeps its open state across re-renders.

    import { Button } from "@/components/markas/Button";
    import { Modal } from "@/components/markas/Modal";
    
    <Modal
      title="Delete project?"
      trigger={<Button variant="danger">Delete</Button>}
      footer={
        <>
          <Button variant="secondary" type="submit" value="cancel">
            Cancel
          </Button>
          <Button variant="danger" type="submit" value="delete">
            Delete
          </Button>
        </>
      }
      onClose={(e) => console.log(e.currentTarget.returnValue)}
    >
      The project and all of its data will be deleted permanently.
    </Modal>;
    <template>
      <Modal title="Delete project?">
        <template #trigger>
          <Button variant="danger">Delete</Button>
        </template>
    
        The project and all of its data will be deleted permanently.
    
        <template #footer>
          <Button variant="secondary" type="submit" value="cancel">Cancel</Button>
          <Button variant="danger" type="submit" value="delete">Delete</Button>
        </template>
      </Modal>
    </template>
    <script lang="ts">
      import Button from "$lib/components/markas/Button.svelte";
      import Modal from "$lib/components/markas/Modal.svelte";
    </script>
    
    <Modal
      title="Delete project?"
      onclose={(e) => console.log(e.currentTarget.returnValue)}
    >
      {#snippet trigger()}
        <Button variant="danger">Delete</Button>
      {/snippet}
    
      The project and all of its data will be deleted permanently.
    
      {#snippet footer()}
        <Button variant="secondary" type="submit" value="cancel">Cancel</Button>
        <Button variant="danger" type="submit" value="delete">Delete</Button>
      {/snippet}
    </Modal>
    ---
    import Button from "@/components/markas/Button.astro";
    import Modal from "@/components/markas/Modal.astro";
    ---
    
    <Modal title="Delete project?">
      <Button slot="trigger" variant="danger">Delete</Button>
    
      The project and all of its data will be deleted permanently.
    
      <Fragment slot="footer">
        <Button variant="secondary" type="submit" value="cancel">Cancel</Button>
        <Button variant="danger" type="submit" value="delete">Delete</Button>
      </Fragment>
    </Modal>

    A small bundled script opens every modal on the page. It also works after view transitions.

    import { Component } from "@angular/core";
    import { Button } from "./markas/button.component";
    import { Modal } from "./markas/modal.component";
    
    @Component({
      selector: "app-danger-zone",
      imports: [Button, Modal],
      template: `
        <markas-modal title="Delete project?" (closed)="onClosed()">
          <button markas-button trigger variant="danger">Delete</button>
    
          The project and all of its data will be deleted permanently.
    
          <ng-container footer>
            <button markas-button variant="secondary" type="submit" value="cancel">
              Cancel
            </button>
            <button markas-button variant="danger" type="submit" value="delete">
              Delete
            </button>
          </ng-container>
        </markas-modal>
      `,
    })
    export class DangerZone {
      onClosed() {}
    }
    • The value of the button that closed the modal is available as dialog.returnValue in the close event.
    • To open the modal from code, call document.getElementById(id).showModal().
    • The close button is labelled “Close”. Translate it with closeLabel (Blade: close-label).

    Props

    NameTypeDefaultDescription
    titlestring-Dialog title, also used for aria-labelledby.
    triggerslot / ReactNode / snippet-Element that opens the modal when clicked. Angular: an element with the trigger attribute.
    footerslot / ReactNode / snippet-Action area. Wrapped in form method=dialog, so a type=submit button closes the modal. Angular: an element with the footer attribute.
    idstringautoDialog id. Use it to open the modal from elsewhere with showModal().
    closeLabelstringCloseAccessible label of the close button.
    closedoutput<void>-Angular only. Emits when the modal closes.

    Accessibility

    • Uses dialog with showModal(), so focus stays inside and the page behind is inert.
    • Escape closes the modal and returns focus to the trigger.
    • Clicking outside the panel (the backdrop) closes the modal.
    • The close button is labelled by closeLabel.

    Related components

    More overlay components with the same classes in every framework.