Overlays

Modal

A window above the page, for a task the user finishes or cancels before going back to the page.

Usage

Put the element that opens the modal in the default slot, and what the modal shows in the body and footer slots. The title and the description go at the top, and the close button is added for you.

<script setup lang="ts">
import { ref } from 'vue'

const merchant = ref('Acme Corp')
const category = ref('salary')
const categoryOptions = [
  { value: 'salary', label: 'Salary' },
  { value: 'freelance', label: 'Freelance' },
  { value: 'refund', label: 'Refund' },
]
</script>

<template>
  <KModal title="Edit transaction" description="Change how this transaction appears in your reports.">
    <KButton label="Edit transaction" />
    <template #body>
      <div class="flex flex-col gap-3">
        <KTextField v-model="merchant" label="Merchant" size="3xl" />
        <KSelectField v-model="category" label="Category" :options="categoryOptions" size="3xl" />
      </div>
    </template>
    <template #footer="{ close }">
      <KButton label="Cancel" variant="soft" color="gray" @click="close" />
      <KButton label="Save changes" @click="close" />
    </template>
  </KModal>
</template>

The modal adds no element around yours: it listens on your element directly and gives it aria-haspopup, aria-expanded and aria-controls. The title names the modal for screen readers, and the description describes it.

Every slot gets a close function. The fields inside the modal sit on its surface, so their floating label needs nothing more: see On a card.

To ask a quick yes or no question, useConfirm is shorter. To open a modal from your code and wait for what it returns, see useOverlay.

Size

Use the size prop to make the modal sm (420px), md (512px, default), lg (640px) or xl (768px) wide. On a small screen, the modal takes the whole width, minus 16px on each side.

<script setup lang="ts">
const modalSizes = ['sm', 'md', 'lg', 'xl'] as const
</script>

<template>
  <div class="flex flex-wrap gap-3">
    <KModal
      v-for="modalSize in modalSizes"
      :key="modalSize"
      :size="modalSize"
      :title="`Size ${modalSize}`"
      description="On a small screen, the modal takes the whole width, minus 16px on each side."
    >
      <KButton :label="modalSize" variant="outline" color="gray" />
    </KModal>
  </div>
</template>

Full screen

Set fullscreen to cover the whole screen, for a long form or a document.

<script setup lang="ts">
import { ref } from 'vue'

const client = ref('Northwind Traders')
const reference = ref('INV-2026-118')
const amount = ref('1,280.00')
const dueDate = ref('Dec 15, 2026')
</script>

<template>
  <KModal title="New invoice" description="Bill a client for work you have done." fullscreen dividers>
    <KButton label="New invoice" />
    <template #body>
      <div class="grid gap-3 sm:grid-cols-2">
        <KTextField v-model="client" label="Client" size="3xl" />
        <KTextField v-model="reference" label="Reference" size="3xl" />
        <KTextField v-model="amount" label="Amount" inputmode="decimal" size="3xl" />
        <KTextField v-model="dueDate" label="Due date" size="3xl" />
      </div>
    </template>
    <template #footer="{ close }">
      <KButton label="Cancel" variant="soft" color="gray" @click="close" />
      <KButton label="Create invoice" @click="close" />
    </template>
  </KModal>
</template>

Long content

The modal is never taller than the screen minus 16px at the top and the bottom. When its body is longer, the body scrolls and the title and the footer stay in view. Set dividers to draw a line between them and the body.

<script setup lang="ts">
const termsParagraphs = [
  'Kuina keeps your transactions, budgets and receipts so you can see where your money goes. You stay the owner of everything you add.',
  'We store your data in the region you chose when you created your account, and we never sell it. Your bank connections are read only.',
  'You can export every transaction as a CSV file at any time, and delete your account from the settings. Deleted data is gone after 30 days.',
  'Receipts you upload are scanned to fill in the merchant, the date and the amount. You can correct anything the scan gets wrong.',
  'Shared budgets are visible to the people you invite. They can add transactions but cannot see your other accounts.',
  'We may change these terms. When we do, we tell you by email at least 30 days before the change applies.',
]
</script>

<template>
  <KModal title="Terms of service" description="Last updated on November 1, 2026." dividers>
    <KButton label="Read the terms" variant="outline" color="gray" />
    <template #body>
      <div class="flex flex-col gap-3 text-sm text-muted">
        <p v-for="termsParagraph in termsParagraphs" :key="termsParagraph">{{ termsParagraph }}</p>
      </div>
    </template>
    <template #footer="{ close }">
      <KButton label="Decline" variant="soft" color="gray" @click="close" />
      <KButton label="Accept" @click="close" />
    </template>
  </KModal>
</template>

Alert

Set alert when the modal asks the user to confirm something they cannot undo. Screen readers then announce it as an alert. Put autofocus on the safest button, so a quick Enter does no harm.

<script setup lang="ts">
import { ref } from 'vue'

const deletesReceipts = ref(true)
</script>

<template>
  <KModal
    title="Delete transaction?"
    description="This will permanently delete the Acme Corp payment of $4,850.00. This can't be undone."
    size="sm"
    alert
    translucent
  >
    <KButton label="Delete transaction" variant="soft" color="danger" />
    <template #body>
      <KCheckbox v-model="deletesReceipts" label="Also delete the receipts attached to this transaction" />
    </template>
    <template #footer="{ close }">
      <KButton label="Cancel" variant="soft" color="gray" autofocus @click="close" />
      <KButton label="Delete transaction" variant="soft" color="danger" @click="close" />
    </template>
  </KModal>
</template>

Translucent

Set translucent to let the page behind the modal show through a blur.

<template>
  <KModal
    title="Your November report is ready"
    description="See where your money went this month, by category and by merchant."
    size="sm"
    translucent
  >
    <KButton label="Show report" variant="soft" color="gray" />
    <template #footer="{ close }">
      <KButton label="Later" variant="soft" color="gray" @click="close" />
      <KButton label="Open report" @click="close" />
    </template>
  </KModal>
</template>

Close button

Set :close="false" to remove the close button, or pass it the props of a Button to change it. close-label names it for screen readers, Close by default.

<template>
  <KModal title="Edit transaction" close-label="Close the editor" :close="{ variant: 'soft' }">
    <KButton label="Edit transaction" />
  </KModal>
</template>

Prevent closing

Set :dismissible="false" to keep the modal open when the user presses Esc or clicks outside. The modal shakes instead, and sends close-prevented. Only close from a slot, or v-model:open, closes it then.

Closing was prevented 0 times.

<script setup lang="ts">
import { ref } from 'vue'

const preventedCloseCount = ref(0)
</script>

<template>
  <div class="flex flex-wrap items-center gap-3">
    <KModal
      title="Importing your statement"
      description="Wait until the 214 transactions are imported, or cancel the import."
      :dismissible="false"
      :close="false"
      @close-prevented="preventedCloseCount++"
    >
      <KButton label="Import statement" />
      <template #footer="{ close }">
        <KButton label="Cancel import" variant="soft" color="gray" @click="close" />
      </template>
    </KModal>
    <p class="text-sm text-muted">Closing was prevented {{ preventedCloseCount }} times.</p>
  </div>
</template>

Open state

Use v-model:open to open and close the modal from your code. The default slot can then stay empty. after-open and after-close are sent once the modal has finished appearing or disappearing.

The modal is closed, and finished closing 0 times.

<script setup lang="ts">
import { ref } from 'vue'

const isModalOpen = ref(false)
const closingCount = ref(0)
</script>

<template>
  <div class="flex flex-wrap items-center gap-3">
    <KButton label="Sync accounts" variant="outline" color="gray" @click="isModalOpen = true" />
    <p class="text-sm text-muted">
      The modal is {{ isModalOpen ? 'open' : 'closed' }}, and finished closing {{ closingCount }} times.
    </p>
  </div>
  <KModal
    v-model:open="isModalOpen"
    title="Accounts synced"
    description="Your 3 accounts are up to date."
    size="sm"
    @after-close="closingCount++"
  >
    <template #footer="{ close }">
      <KButton label="Done" @click="close" />
    </template>
  </KModal>
</template>

The same functions are on the component itself, with a template ref: modalRef.value.open(), close() and shake().

Your own layout

Use the content slot to replace everything inside the modal, close button included. Name the modal yourself with aria-label: attributes given to KModal go to the modal window.

<script setup lang="ts">
import { Sparkles } from 'lucide-vue-next'
</script>

<template>
  <KModal size="sm" aria-label="Welcome to Kuina">
    <KButton label="Show welcome" variant="outline" color="gray" />
    <template #content="{ close }">
      <div class="flex flex-col items-center gap-3 px-6 py-8 text-center">
        <Sparkles class="size-8 text-primary" />
        <h2 class="text-lg/6 font-semibold">Welcome to Kuina</h2>
        <p class="text-muted">Connect a bank account to see your transactions here.</p>
        <KButton label="Get started" class="mt-2" @click="close" />
      </div>
    </template>
  </KModal>
</template>

To keep the layout and only change the top, use the header slot, or the title, description and actions slots for one part of it.

Focus on open

When the modal opens, the focus goes to the element with autofocus inside it, or else to the first element that can take the focus. When it closes, the focus goes back to the element that opened it.

Behavior

The modal closes when:

  • close is called, or the close button is clicked;
  • Esc is pressed;
  • a pointer goes down on the dark layer around it.

While it is open, the rest of the page can't be clicked, focused or read by screen readers, and it doesn't scroll. A Menu, a Select or a Popover opened inside the modal works as usual, and Esc closes it before the modal. A modal can open another modal: the newest one stays on top.

Keyboard

KeyAction
Enter SpaceOn the element, opens the modal.
TabMoves through the modal.
EscCloses the modal, or shakes it when it can't be dismissed.

Customization

Use the ui prop to change the classes of each part, and class for the modal window (panel). Your classes always win: rounded-sm replaces the default rounded-2xl instead of being added to it.

<template>
  <KModal title="Edit transaction" :ui="{ panel: 'rounded-sm', overlay: 'backdrop-blur-sm' }">
    <KButton label="Edit transaction" />
  </KModal>
</template>

The parts are the layer that holds everything, the dark overlay, the panel, and inside it the header, headerText, title, description, actions, body, footer and closeButton. The overlay… and panel… parts ending in Entering, Leaving and Hidden hold the animations.

API

Props

PropTypeDefault
openbooleanfalse
titlestring
descriptionstring
size'sm' | 'md' | 'lg' | 'xl''md'
fullscreenbooleanfalse
dividersbooleanfalse
translucentbooleanfalse
closeboolean | ButtonPropstrue
closeLabelstring'Close'
dismissiblebooleantrue
alertbooleanfalse
ui{ layer?, overlay?, overlayEntering?, overlayLeaving?, overlayHidden?, panel?, panelEntering?, panelLeaving?, panelHidden?, header?, headerText?, title?, description?, actions?, body?, footer?, closeButton? }
classstring

Slots

SlotPropsDescription
defaultThe element that opens the modal. Optional with v-model:open.
header{ close }Replaces the title, the description and the actions.
titleReplaces the text of the title.
descriptionReplaces the text of the description.
actions{ close }Buttons next to the title.
body{ close }The main content. Scrolls when it is too long.
footer{ close }The buttons at the bottom.
content{ close }Replaces everything inside the modal.

Emits

EventPayload
update:openboolean
closePrevented
afterOpen
afterClose

Expose

MethodDescription
open()Opens the modal.
close()Closes the modal.
shake()Shakes the modal sideways once.
Copyright © 2026