Floating Vue (v-tooltip)

2.1.3 · active · verified Sun Apr 19

Floating Vue, currently at version 5.x, is a robust and flexible library for creating tooltips, popovers, dropdowns, and menus in Vue 3 applications. It is the successor to the original `v-tooltip` package, having been rebranded from `floating-vue` v2.x to `v-tooltip` v5.x to streamline versioning and prevent confusion, while retaining the same underlying codebase and functionality. The library leverages `@floating-ui/dom` for efficient and precise anchor positioning, ensuring floating elements are always positioned optimally. It offers both directive-based (`v-tooltip`, `v-close-popper`) and component-based (`VDropdown`, `VTooltip`, `VMenu`) usage, supporting a wide range of interactive UI patterns. Releases are regular, with a focus on Vue 3 compatibility, performance, and improved TypeScript typings. Key differentiators include its extensive configuration options, powerful theming capabilities, and seamless integration with Vue 3's composition API.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates both the `v-tooltip` directive and the `VDropdown` component from Floating Vue in a Vue 3 `script setup` environment, including global registration and CSS import.

<!-- App.vue -->
<script setup lang="ts">
import { ref } from 'vue';
import { VTooltip, VDropdown } from 'floating-vue';
import 'floating-vue/dist/style.css'; // Don't forget to import the CSS

const tooltipMessage = ref('Hello from v-tooltip directive!');
const dropdownContent = ref('This is a dropdown menu.');
</script>

<template>
  <main class="container">
    <h1>Floating Vue (v-tooltip) Demo</h1>
    <p>Using the v-tooltip directive:</p>
    <button v-tooltip="tooltipMessage" class="btn">
      Hover me (Directive)
    </button>

    <p>Using the VDropdown component:</p>
    <VDropdown>
      <button class="btn">Click for Dropdown</button>
      <template #popper>
        <div class="dropdown-content">
          {{ dropdownContent }}
          <button class="btn">Action 1</button>
          <button class="btn">Action 2</button>
        </div>
      </template>
    </VDropdown>
  </main>
</template>

<style>
body { font-family: sans-serif; margin: 20px; }
.container { display: flex; flex-direction: column; gap: 20px; align-items: flex-start; }
.btn { padding: 8px 15px; border: 1px solid #ccc; border-radius: 4px; background-color: #f0f0f0; cursor: pointer; }
.dropdown-content { padding: 10px; background: white; border: 1px solid #eee; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); display: flex; flex-direction: column; gap: 5px; }
</style>

<!-- main.ts or main.js -->
<script type="module">
import { createApp } from 'vue';
import App from './App.vue';
import FloatingVue from 'floating-vue';
import 'floating-vue/dist/style.css';

const app = createApp(App);
app.use(FloatingVue);
app.mount('#app');
</script>

view raw JSON →