Vue Final Modal

4.5.5 · active · verified Sun Apr 19

Vue Final Modal is a highly optimized and lightweight modal library specifically designed for Vue 3 applications, providing robust dialog, popup, and overlay functionalities. The current stable version is 4.5.5, with an active beta development for version 5.0.0, indicating a consistent release cadence with a focus on ongoing improvements and new features. Key differentiators include its balance of power and lightweight footprint, extensive customization options, and strong TypeScript support, making it suitable for complex UIs while maintaining performance. It handles common modal concerns like accessibility, scroll locking, and stacking contexts effectively, providing a comprehensive solution for interactive overlays in Vue 3 projects.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates two ways to use Vue Final Modal: declarative with v-model and programmatically using the `useModal` composable. It shows basic modal opening/closing and integrates the `ModalsContainer` for programmatic modals.

import { createApp, ref } from 'vue'
import { VueFinalModal, useModal, ModalsContainer } from 'vue-final-modal'

const app = createApp({
  template: `
    <button @click="openModal">Open Modal</button>
    <VueFinalModal
      v-model="showModal"
      classes="flex justify-center items-center"
      content-class="relative flex flex-col max-h-full mx-4 p-4 border dark:border-gray-800 rounded bg-white dark:bg-gray-900"
      :overlay-transition="'vfm-fade'"
      :content-transition="'vfm-slide-up'"
      @before-close="beforeClose"
    >
      <h1 class="text-xl">Hello, Vue Final Modal!</h1>
      <p>This is a custom modal opened via a ref.</p>
      <button class="mt-4 p-2 bg-blue-500 text-white rounded" @click="showModal = false">Close</button>
    </VueFinalModal>
    <button @click="openProgrammaticModal">Open Programmatic Modal</button>
    <ModalsContainer />
  `,
  setup() {
    const showModal = ref(false)
    const { open, close } = useModal({
      component: VueFinalModal,
      attrs: {
        title: 'Programmatic Modal',
        onUpdateModelValue: (val) => console.log('Programmatic modal v-model:', val)
      },
      slots: {
        default: '<p>This modal was opened programmatically!</p><button @click="options.close">Close</button>'
      }
    })

    function openModal() {
      showModal.value = true
    }

    function beforeClose() {
      console.log('Modal is about to close')
      // You can prevent closing here if needed
      // return false
    }

    function openProgrammaticModal() {
      open()
    }

    return { showModal, openModal, beforeClose, openProgrammaticModal }
  }
})

app.component('VueFinalModal', VueFinalModal)
app.mount('#app')

view raw JSON →