### Install Floating Vue with Options Source: https://floating-vue.starpad.dev/guide/config Use the `Vue.use()` method with an options object to configure Floating Vue globally during installation. ```javascript import FloatingVue from 'floating-vue' Vue.use(FloatingVue, options) ``` -------------------------------- ### Install Floating Vue v1 for Vue 2 with npm Source: https://floating-vue.starpad.dev/guide/installation Install version 1 of floating-vue, specifically for compatibility with Vue 2 projects, using npm. ```bash npm i floating-vue@vue2 ``` -------------------------------- ### Install Floating Vue v1 for Vue 2 with pnpm Source: https://floating-vue.starpad.dev/guide/installation Install version 1 of floating-vue, specifically for compatibility with Vue 2 projects, using pnpm. ```bash pnpm add floating-vue@vue2 ``` -------------------------------- ### Install Floating Vue with npm Source: https://floating-vue.starpad.dev/guide Use this command to add the floating-vue package to your project using npm. ```bash npm i floating-vue ``` -------------------------------- ### Custom Theme Styling Source: https://floating-vue.starpad.dev/guide/css Provides a comprehensive example of styling a custom theme named `my-theme`, including background, borders, shadows, and arrow styles. ```css .v-popper--theme-my-theme .v-popper__inner { background: #fff; color: black; padding: 24px; border-radius: 6px; border: 1px solid #ddd; box-shadow: 0 6px 30px rgba(0, 0, 0, .1); } .v-popper--theme-my-theme .v-popper__arrow-inner { visibility: visible; border-color: #fff; } .v-popper--theme-my-theme .v-popper__arrow-outer { border-color: #ddd; } /* Transition */ .v-popper--theme-my-theme.v-popper__popper--hidden { visibility: hidden; opacity: 0; transition: opacity .15s, visibility .15s; } .v-popper--theme-my-theme.v-popper__popper--shown { visibility: visible; opacity: 1; transition: opacity .15s; } .v-popper--theme-my-theme.v-popper__popper--skip-transition { transition: none !important; } ``` -------------------------------- ### Install Floating Vue with pnpm Source: https://floating-vue.starpad.dev/guide Use this command to add the floating-vue package to your project using pnpm. ```bash pnpm add floating-vue ``` -------------------------------- ### Global Configuration Migration: v-tooltip v2 to Floating Vue Source: https://floating-vue.starpad.dev/migration/migration-from-v2 Compares the global configuration objects of v-tooltip v2 and floating-vue. Use the 'After' example to replicate v-tooltip v2's default configuration in floating-vue. ```javascript { defaultPlacement: 'top', defaultClass: 'vue-tooltip-theme', defaultTargetClass: 'has-tooltip', defaultHtml: true, defaultTemplate: '', defaultArrowSelector: '.tooltip-arrow, .tooltip__arrow', defaultInnerSelector: '.tooltip-inner, .tooltip__inner', defaultDelay: 0, defaultTrigger: 'hover focus', defaultOffset: 0, defaultContainer: 'body', defaultBoundariesElement: undefined, defaultPopperOptions: {}, defaultLoadingClass: 'tooltip-loading', defaultLoadingContent: '...', autoHide: true, defaultHideOnTargetClick: true, disposeTimeout: 5000, popover: { defaultPlacement: 'bottom', defaultClass: 'vue-popover-theme', defaultBaseClass: 'tooltip popover', defaultWrapperClass: 'wrapper', defaultInnerClass: 'tooltip-inner popover-inner', defaultArrowClass: 'tooltip-arrow popover-arrow', defaultOpenClass: 'open', defaultDelay: 0, defaultTrigger: 'click', defaultOffset: 0, defaultContainer: 'body', defaultBoundariesElement: undefined, defaultPopperOptions: {}, defaultAutoHide: true, defaultHandleResize: true, }, } ``` ```javascript { placement: 'top', delay: 0, distance: 0, container: 'body', boundary: undefined, autoHide: true, disposeTimeout: 5000, themes: { tooltip: { html: true, triggers: ['hover', 'focus'], hideTriggers: triggers => [...triggers, 'click'], loadingContent: '...', }, dropdown: { placement: 'bottom', delay: 0, triggers: ['click'], distance: 0, container: 'body', boundary: undefined, autoHide: true, handleResize: true, }, }, } ``` -------------------------------- ### Define a Themed Component with Custom Options Source: https://floating-vue.starpad.dev/guide/themes Create a reusable component that uses a specific theme by extending `PopperWrapper` and setting `vPopperTheme`. This example defines an `info-dropdown` theme. ```js Vue.use(FloatingVue, { themes: { 'info-dropdown': { $extend: 'dropdown', // Other options (see the 'Global options' section) placement: 'right', delay: 300, }, }, }) ``` -------------------------------- ### Install Floating Vue v1 for Vue 2 with yarn Source: https://floating-vue.starpad.dev/guide/installation Install version 1 of floating-vue, specifically for compatibility with Vue 2 projects, using yarn. ```bash yarn add floating-vue@vue2 ``` -------------------------------- ### Install Floating Vue with yarn Source: https://floating-vue.starpad.dev/guide Use this command to add the floating-vue package to your project using yarn. ```bash yarn add floating-vue ``` -------------------------------- ### Custom Popper Component Example Source: https://floating-vue.starpad.dev/guide/custom-component This example demonstrates how to create a custom wrapper component for Floating Vue's Popper and PopperContent, integrating mixins and props for theme and target nodes. ```html ``` -------------------------------- ### Mobile Poppers with Custom Logic Source: https://floating-vue.starpad.dev/guide/component This example demonstrates how to handle mobile popper behavior, including disabling positioning and applying custom CSS classes for fixed positioning and body scroll management. ```html ``` -------------------------------- ### Custom Theme Configuration Source: https://floating-vue.starpad.dev/migration/migration-from-v2 Configure custom themes for floating components by extending existing themes or defining new ones with specific props and CSS classes. This example shows how to create a 'select' theme extending the 'dropdown' theme. ```javascript app.use(FloatingVue, { themes: { select: { $extend: 'dropdown', // builtin theme triggers: ['click', 'touch', 'focus'], distance: 6, delay: 0, }, 'multi-select': { $extend: 'select', triggers: ['click', 'touch'], distance: 10, }, }, }) ``` -------------------------------- ### Create and Manage Tooltip Source: https://floating-vue.starpad.dev/api Creates a tooltip on a given element and manages its lifecycle. Use `destroyTooltip` to clean up the tooltip when it's no longer needed. This example demonstrates creating a tooltip for a clipboard success message. ```javascript import { createTooltip, destroyTooltip } from 'floating-vue' export function clipboardSuccess (el) { const tooltip = createTooltip(el, { triggers: [], content: 'Text copied!', }) tooltip.show() setTimeout(() => { tooltip.hide() // Transition setTimeout(() => { destroyTooltip(el) }, 400) }, 600) } ``` -------------------------------- ### Install plugin into Vue 2 app Source: https://floating-vue.starpad.dev/guide/installation Use the FloatingVue plugin with Vue 2 by importing it and calling `Vue.use()`. ```javascript import Vue from 'vue' import FloatingVue from 'floating-vue' Vue.use(FloatingVue) ``` -------------------------------- ### Install plugin in browser app Source: https://floating-vue.starpad.dev/guide/installation Use the FloatingVue plugin with your Vue app instance when including the script via CDN. ```javascript app.use(FloatingVue) ``` -------------------------------- ### Import directives and components in Vue SFC Source: https://floating-vue.starpad.dev/guide/installation Import specific directives and components directly within a Vue Single File Component's script setup. ```vue ``` -------------------------------- ### Using Built-in Components (VDropdown, VMenu, VTooltip) Source: https://floating-vue.starpad.dev/migration/migration-from-v2 Leverage pre-built components for common UI patterns like dropdowns, menus, and tooltips. Each component uses a template slot for the popper content. ```html ``` -------------------------------- ### Enable Instant Move with `instantMove` Source: https://floating-vue.starpad.dev/api When another popper is open, use `instant-move` to skip delays and CSS transitions, making the popper appear to move instantly to its new position. ```html ``` -------------------------------- ### Hide All Poppers Source: https://floating-vue.starpad.dev/api Call this function to hide all currently visible poppers. No specific setup is required. ```javascript import { hideAllPoppers } from 'floating-vue' hideAllPoppers() ``` -------------------------------- ### Basic v-tooltip directive usage Source: https://floating-vue.starpad.dev/api Demonstrates the basic structure for applying the v-tooltip directive to an HTML element. The directive accepts an object for options. ```html ``` ```css .v-popper--tooltip-loading .v-popper__inner { color: #77aaff; } ``` ```html ``` -------------------------------- ### show Source: https://floating-vue.starpad.dev/api Event emitted when the popper is about to be shown. ```APIDOC ## `show` When the popper is going to be shown. ``` -------------------------------- ### Use directives and components directly Source: https://floating-vue.starpad.dev/guide/installation Import and register directives (like v-tooltip) and components (like Dropdown) individually if you prefer not to use the global plugin. ```javascript import { // Directives vTooltip, vClosePopper, // Components Dropdown, Tooltip, Menu } from 'floating-vue' app.directive('tooltip', vTooltip) app.directive('close-popper', vClosePopper) app.component('VDropdown', Dropdown) app.component('VTooltip', Tooltip) app.component('VMenu', Menu) ``` -------------------------------- ### Enable Automatic Resize Handling with `handleResize` Source: https://floating-vue.starpad.dev/api Automatically update the popper's position when its size changes by enabling the `handle-resize` prop. ```html ``` -------------------------------- ### v-tooltip with Placement Modifier Source: https://floating-vue.starpad.dev/guide/directive Specify the tooltip's placement using modifiers like `.bottom-start`. Refer to the documentation for a full list of available placement options. ```html ``` -------------------------------- ### `instantMove` Prop Source: https://floating-vue.starpad.dev/api Skips delays and CSS transitions when another popper is open, making the current popper appear to move instantly. ```APIDOC ## `instantMove` ### Description Boolean: skip delay & CSS transitions when another popper is open, so that the popper appear to instanly move to the new position. ### Example ```html ``` ``` -------------------------------- ### Enable Auto Boundary Max Size with `autoBoundaryMaxSize` Source: https://floating-vue.starpad.dev/api Allow Floating Vue to resize the popper's inner container to fit the available space within the boundary using `auto-boundary-max-size`. This is useful for dropdowns that need to shrink. ```html ``` -------------------------------- ### v-tooltip with object content Source: https://floating-vue.starpad.dev/api Applies a tooltip with specified options, including content, to a button. The content can be a string, a function, or a Promise. ```html ``` -------------------------------- ### v-tooltip with loading content Source: https://floating-vue.starpad.dev/api Specifies a fallback message to display while the actual tooltip content is being loaded asynchronously. This improves user experience during content fetching. ```html ``` -------------------------------- ### `shown` Prop Source: https://floating-vue.starpad.dev/api Controls the visibility of the popper. It's recommended to use this with no trigger events for manual control. ```APIDOC ## `shown` ### Description Boolean that shows or hide the popper. You should probably use no trigger events (manual mode). ### Example ```html ``` ``` -------------------------------- ### Theme Inheritance with CSS Classes Source: https://floating-vue.starpad.dev/guide/css Demonstrates how CSS classes are inherited when one theme extends another. The parent theme's CSS class is automatically included. ```javascript Vue.use(VTooltip, { themes: { 'info-tooltip': { $extend: 'tooltip', }, }, }) // The `themeClasses` will be: // [ // 'v-popper--theme-info-tooltip', // 'v-popper--theme-tooltip', // ] ``` -------------------------------- ### Tooltip Loading State Source: https://floating-vue.starpad.dev/guide/css When a tooltip's content is loading (e.g., from a promise), the popper element receives the `v-popper--tooltip-loading` class. This can be used for visual feedback. ```html
``` -------------------------------- ### Multi-level Theme Inheritance Source: https://floating-vue.starpad.dev/guide/css Illustrates CSS class inheritance across multiple levels of theme extension. All parent theme classes are included. ```javascript Vue.use(VTooltip, { themes: { 'info-tooltip': { $extend: 'tooltip', }, 'other-tooltip': { $extend: 'info-tooltip', } }, }) // The `themeClasses` will be: // [ // 'v-popper--theme-other-tooltip', // 'v-popper--theme-info-tooltip', // 'v-popper--theme-tooltip', // ] ``` -------------------------------- ### v-tooltip with Object Notation Source: https://floating-vue.starpad.dev/guide/directive Use an object for the `v-tooltip` directive to configure content and other component props. This allows for more advanced customization. ```html ``` -------------------------------- ### apply-hide Source: https://floating-vue.starpad.dev/api Event emitted after the hide delay has passed. ```APIDOC ## `apply-hide` Emitted after the hide delay. ``` -------------------------------- ### Customize CSS for a Custom Theme Source: https://floating-vue.starpad.dev/guide/themes Style your custom theme by targeting the generated CSS class, typically in the format `.v-popper--theme-[your-theme-name]`. This allows for specific visual adjustments. ```css .v-popper--theme-info-tooltip { .v-popper__inner { background: #004499; } .v-popper__arrow-inner { border-color: #004499; } } ``` -------------------------------- ### Apply Custom Theme to Directive Source: https://floating-vue.starpad.dev/guide/themes Use the newly created custom theme by specifying its name in the `theme` prop of the `v-tooltip` directive. Ensure the `content` prop is also set. ```html ``` -------------------------------- ### Basic VDropdown Component Source: https://floating-vue.starpad.dev/guide/component Use the VDropdown component for basic popovers. The popper content must be passed to the #popper slot. It uses the 'dropdown' theme by default. ```html ``` -------------------------------- ### VTooltip Component for Advanced Tooltips Source: https://floating-vue.starpad.dev/guide/component Use the VTooltip component for tooltips with rich content. It utilizes the 'tooltip' theme, similar to the v-tooltip directive. ```html Sponsor me ``` -------------------------------- ### `handleResize` Prop Source: https://floating-vue.starpad.dev/api When enabled, the popper's position is automatically updated if its size changes. ```APIDOC ## `handleResize` ### Description Boolean: Automatically update the popper position if its size changes. ### Example ```html ``` ``` -------------------------------- ### Change Popper Theme with `theme` Prop Source: https://floating-vue.starpad.dev/guide/themes Use the `theme` prop on a directive or component to apply a different theme. This allows for quick style and behavior changes. ```html ``` -------------------------------- ### Group Popovers with `showGroup` Source: https://floating-vue.starpad.dev/api Manage groups of popovers by setting the `show-group` prop. Popovers with different or unset `showGroup` values will be closed when one is shown. ```html ``` -------------------------------- ### VDropdown with Custom Triggers Source: https://floating-vue.starpad.dev/guide/component Customize popper visibility by specifying custom triggers. Use an empty array for manual control and the 'shown' prop. ```html ``` ```html ``` -------------------------------- ### `overflowPadding` Prop Source: https://floating-vue.starpad.dev/api Sets virtual padding within the boundary to help prevent the popper from overflowing, measured in pixels. ```APIDOC ## `overflowPadding` ### Description Virtual padding in the `boundary` used to prevent the popper overflow (pixels). ### Example ```html ``` ``` -------------------------------- ### Default Floating Vue Configuration Object Source: https://floating-vue.starpad.dev/guide/config This object outlines all available global configuration options and their default values, including settings for tooltips, dropdowns, and menus. ```javascript export const config: FloatingVueConfig = { // Disable popper components disabled: false, // Default position offset along main axis (px) distance: 5, // Default position offset along cross axis (px) skidding: 0, // Default container where the tooltip will be appended container: 'body', // Element used to compute position and size boundaries boundary: undefined, // Skip delay & CSS transitions when another popper is shown, so that the popper appear to instanly move to the new position. instantMove: false, // Auto destroy tooltip DOM nodes (ms) disposeTimeout: 5000, // Triggers on the popper itself popperTriggers: [], // Positioning strategy strategy: 'absolute', // Prevent overflow preventOverflow: true, // Flip to the opposite placement if needed flip: true, // Shift on the cross axis to prevent the popper from overflowing shift: true, // Overflow padding (px) overflowPadding: 0, // Arrow padding (px) arrowPadding: 0, // Compute arrow overflow (useful to hide it) arrowOverflow: true, /** * By default, compute autohide on 'click'. */ autoHideOnMousedown: false, // Themes themes: { tooltip: { // Default tooltip placement relative to target element placement: 'top', // Default events that trigger the tooltip triggers: ['hover', 'focus', 'touch'], // Close tooltip on click on tooltip target hideTriggers: events => [...events, 'click'], // Delay (ms) delay: { show: 200, hide: 0, }, // Update popper on content resize handleResize: false, // Enable HTML content in directive html: false, // Displayed when tooltip content is loading loadingContent: '...', }, dropdown: { // Default dropdown placement relative to target element placement: 'bottom', // Default events that trigger the dropdown triggers: ['click'], // Delay (ms) delay: 0, // Update popper on content resize handleResize: true, // Hide on click outside autoHide: true, }, menu: { $extend: 'dropdown', triggers: ['hover', 'focus'], popperTriggers: ['hover', 'focus'], delay: { show: 0, hide: 400, }, }, }, } ``` -------------------------------- ### Include via CDN Source: https://floating-vue.starpad.dev/guide/installation Include the Floating Vue JavaScript file directly in your HTML for browser usage. ```html ``` -------------------------------- ### Update Offset Prop: Distance and Skidding Source: https://floating-vue.starpad.dev/migration/migration-from-v3 Replace the 'offset' prop with 'distance' and 'skidding' for more explicit control over positioning. ```html ``` ```html ``` -------------------------------- ### Enable Cross-Axis Shifting with `shiftCrossAxis` Source: https://floating-vue.starpad.dev/api Prevent the popper from overflowing the boundary by adjusting its position along the cross axis using the `shift-cross-axis` prop. ```html ``` -------------------------------- ### Extend Theme and Reset CSS Source: https://floating-vue.starpad.dev/guide/themes Extend an existing theme but disable the inheritance of default CSS classes by setting `$resetCss` to `true`. This allows for complete CSS customization. ```js Vue.use(FloatingVue, { themes: { 'info-tooltip': { $extend: 'tooltip', $resetCss: true, }, }, }) ``` -------------------------------- ### Close All Poppers with v-close-popper.all Source: https://floating-vue.starpad.dev/guide/component Use the `.all` modifier with the `v-close-popper` directive to close all open poppers on the page. ```html Close All ``` -------------------------------- ### Use directives and components directly in Vue 2 Source: https://floating-vue.starpad.dev/guide/installation Register directives and components globally for Vue 2 if not using the plugin. ```javascript import Vue from 'vue' import { // Directives vTooltip, vClosePopper, // Components Dropdown, Tooltip, Menu } from 'floating-vue' Vue.directive('tooltip', vTooltip) Vue.directive('close-popper', vClosePopper) Vue.component('VDropdown', Dropdown) Vue.component('VTooltip', Tooltip) Vue.component('VMenu', Menu) ``` -------------------------------- ### VDropdown with Arrow Padding Source: https://floating-vue.starpad.dev/guide/component Configure 'arrow-padding' to prevent the tooltip arrow from glitching when positioned near the reference edges. This sets a limit for the arrow's position within the tooltip. ```html ``` ```html ``` -------------------------------- ### VDropdown with Separate Show/Hide Triggers Source: https://floating-vue.starpad.dev/guide/component Define distinct triggers for showing and hiding the popper using 'showTriggers' and 'hideTriggers' props. ```html ``` -------------------------------- ### Default Popper Structure Source: https://floating-vue.starpad.dev/guide/css The default HTML structure for a popper component, including the base `v-popper` class and dynamic classes like `v-popper--shown`. ```html
<!-- themeClasses, 'v-popper--shown' &45;-> <!-- Default slot &45;-
``` -------------------------------- ### Control Flipping with `flip` Source: https://floating-vue.starpad.dev/api Prevent the popper from overflowing the boundary by using an opposite placement if necessary. Set `flip` to `false` to disable this. ```html ``` -------------------------------- ### VDropdown with custom show triggers Source: https://floating-vue.starpad.dev/api Allows overriding the default events that trigger the showing of the popper. This can be a function that modifies the existing triggers list. ```html ``` -------------------------------- ### Recompute All Poppers Source: https://floating-vue.starpad.dev/api Call this function to force a recomputation of the position for all visible poppers. This is useful if popper positions become incorrect due to dynamic content changes. It's also automatically called on window resize. ```javascript import { recomputeAllPoppers } from 'floating-vue' recomputeAllPoppers() ``` -------------------------------- ### `showGroup` Prop Source: https://floating-vue.starpad.dev/api If set, this prop ensures that only poppers with the same `showGroup` value are open simultaneously, closing others. ```APIDOC ## `showGroup` ### Description If set, will close all the open popovers that have a different or unset `showGroup` value. ### Example ```html ``` ``` -------------------------------- ### Enable Auto Max Size for Popper Source: https://floating-vue.starpad.dev/migration/migration-from-v3 Use the 'auto-max-size' prop to allow Floating Vue to automatically adjust the popper's max width and height to fit available space. ```html ``` -------------------------------- ### Define Trigger Content with Default Slot Source: https://floating-vue.starpad.dev/api Use the default slot to provide the content for the trigger part of the popper, typically a button. The slot exposes `shown` (boolean), `show` (method), and `hide` (method) props. ```html ``` -------------------------------- ### `computeTransformOrigin` Prop Source: https://floating-vue.starpad.dev/api Enables the computation of the transform origin for the `.v-popper__wrapper` to facilitate zooming effects relative to the reference element. ```APIDOC ## `computeTransformOrigin` ### Description Computes the transform origin of the `.v-popper__wrapper` to allow zooming effects relative to the reference element. ### Example ```html ``` ``` -------------------------------- ### Update Trigger Prop Source: https://floating-vue.starpad.dev/migration/migration-from-v2 The `trigger` prop is now `triggers` and expects an array of events. Use an empty array for manual triggers. ```html ``` ```html ``` ```html ``` ```html ``` -------------------------------- ### Enable Auto Min Size for Popper Source: https://floating-vue.starpad.dev/migration/migration-from-v2 Restrict the popper's minimum size to match the reference element's size. Useful for form inputs like selects. ```html ``` -------------------------------- ### Unified Popper Props for Directive and Component Source: https://floating-vue.starpad.dev/migration/migration-from-v2 Use the same Popper props for both the directive and component. The directive accepts props directly, while the component uses them as props. ```html ``` ```html ``` -------------------------------- ### VDropdown with Skidding Offset Source: https://floating-vue.starpad.dev/guide/component Use the 'skidding' prop to offset the popper along the reference element's axis. Negative values can be used for relative offsetting. ```html ``` ```html ``` -------------------------------- ### Update Global Configuration Option Source: https://floating-vue.starpad.dev/guide/config Modify a specific global configuration option directly on the `FloatingVue.options` object. ```javascript import FloatingVue from 'floating-vue' FloatingVue.options.distance = 12 ``` -------------------------------- ### Enable Auto Hide with `autoHide` Source: https://floating-vue.starpad.dev/api Automatically hide the popper when a click occurs outside of it by using the `auto-hide` prop. ```html ```