Floating Vue Components

5.2.2 · active · verified Sun Apr 19

floating-vue is a Vue.js library for creating interactive floating UI elements such as tooltips, dropdowns, menus, and popovers. It is built upon the robust Floating UI library for precise and efficient positioning. The current stable version is 5.2.2, with active maintenance demonstrated by frequent patch and minor releases. A key differentiator is its comprehensive integration with Vue 3, providing both components (like VTooltip, VDropdown) and directives (like v-tooltip, v-close-popper) for declarative control over floating elements. The library ships with full TypeScript type definitions, enhancing developer experience and project reliability. It also offers powerful theming capabilities and flexible configuration options to adapt to various design systems.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the installation of Floating Vue, its styling, and the usage of basic `VTooltip` (static and dynamic content) and `VDropdown` components with the `v-close-popper` directive.

import { createApp, ref } from 'vue';
import FloatingVue from 'floating-vue';
import 'floating-vue/dist/style.css';

const App = {
  setup() {
    const message = ref('Hello Floating Vue!');
    const count = ref(0);

    setInterval(() => {
      count.value++;
    }, 2000);

    const dynamicContent = `You have <b>${count.value}</b> new messages.`;

    return {
      message,
      count,
      dynamicContent
    };
  },
  template: `
    <div id="app" class="p-8 flex flex-col items-center space-y-4">
      <h1 class="text-2xl font-bold">Floating Vue Basic Example</h1>

      <VTooltip :distance="10">
        <button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">Hover for Tooltip (Static)</button>
        <template #popper>
          <div class="p-2 bg-gray-700 text-white rounded shadow-lg">
            {{ message }}
          </div>
        </template>
      </VTooltip>

      <VTooltip placement="right" :distance="10">
        <button class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600">Hover for Tooltip (Dynamic)</button>
        <template #popper>
          <div class="p-2 bg-gray-700 text-white rounded shadow-lg" v-html="dynamicContent"></div>
        </template>
      </VTooltip>

      <VDropdown :distance="10">
        <button class="px-4 py-2 bg-purple-500 text-white rounded hover:bg-purple-600">Click for Dropdown</button>
        <template #popper>
          <div class="p-4 bg-white rounded shadow-lg border">
            <p class="mb-2">Dropdown Content</p>
            <button v-close-popper class="px-3 py-1 bg-red-500 text-white rounded hover:bg-red-600">Close Me</button>
          </div>
        </template>
      </VDropdown>
    </div>
  `,
};

const app = createApp(App);
app.use(FloatingVue);
app.mount('#app');

view raw JSON →