Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Floating Panel for Vue UI SDK

A window people can drag, resize, minimize and maximize while the page under it stays usable. A Vue floating panel to use with UI SDK.

On this page9 sections

A floating panel is a small window over the page that people drag by its header, resize from any edge or corner, and minimize or maximize from its title bar. The page under it keeps working, which suits an inspector, a font or color palette, or notes kept open beside the work.

When a task should stop everything else until it's done, use a Dialog instead.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Floating Panel anatomy: header, title, stage trigger, close trigger, body, content, resize trigger

Usage

<script setup lang="ts">
import { createListCollection } from "@/lib/collection"
import { Settings2Icon, XIcon } from "lucide-vue-next"
import { Button } from "@/components/ui/button"
import { Field, FieldLabel } from "@/components/ui/field"
import {
  FloatingPanel, FloatingPanelBody, FloatingPanelCloseTrigger,
  FloatingPanelContent, FloatingPanelControl, FloatingPanelFooter,
  FloatingPanelHeader, FloatingPanelMaximize, FloatingPanelMinimize,
  FloatingPanelRestore, FloatingPanelTitle, FloatingPanelTrigger,
} from "@/components/ui/floating-panel"
import {
  NumberInput, NumberInputDecrement, NumberInputGroup,
  NumberInputIncrement, NumberInputInput,
} from "@/components/ui/number-input"
import {
  Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
} from "@/components/ui/select"

const collection = createListCollection({
  items: ["Inter", "Roboto", "Helvetica", "Geist"],
});
</script>

<template>
  <FloatingPanel :defaultSize="{ height: 300, width: 360 }">
    <FloatingPanelTrigger>
      <template #render="{ props }">
        <Button v-bind="props" variant="outline">Open</Button>
      </template>
    </FloatingPanelTrigger>
    <FloatingPanelContent>
      <FloatingPanelHeader>
        <Settings2Icon />
        <FloatingPanelTitle>Settings</FloatingPanelTitle>
        <FloatingPanelControl>
          <FloatingPanelMinimize />
          <FloatingPanelMaximize />
          <FloatingPanelRestore />
          <FloatingPanelCloseTrigger>
            <template #render="{ props }">
              <Button v-bind="props" aria-label="Close" size="icon-xs">
                <XIcon :aria-hidden="true" />
              </Button>
            </template>
          </FloatingPanelCloseTrigger>
        </FloatingPanelControl>
      </FloatingPanelHeader>
      <FloatingPanelBody>
        <Field>
          <FieldLabel>Font family</FieldLabel>
          <Select :collection="collection" defaultValue="Inter">
            <SelectTrigger class="w-full"><SelectValue /></SelectTrigger>
            <SelectContent>
              <SelectItem v-for="item in collection.items" :item="item" :key="item">
                {{ item }}
              </SelectItem>
            </SelectContent>
          </Select>
        </Field>
        <Field>
          <FieldLabel>Font size</FieldLabel>
          <NumberInput class="w-full" defaultValue="16">
            <NumberInputGroup>
              <NumberInputDecrement />
              <NumberInputInput />
              <NumberInputIncrement />
            </NumberInputGroup>
          </NumberInput>
        </Field>
      </FloatingPanelBody>
      <FloatingPanelFooter><Button variant="outline">Save</Button></FloatingPanelFooter>
    </FloatingPanelContent>
  </FloatingPanel>
</template>

Accessibility

The panel is a role="dialog" named by FloatingPanelTitle. Opening it moves focus to the panel itself, and closing it hands focus back to the trigger. It isn't modal, so focus isn't trapped and the rest of the page keeps working. While the panel has focus, the arrow keys move it and Alt with an arrow resizes it, so neither needs a pointer. The minimize, maximize and restore buttons come with labels, and a close trigger with only an icon is named Close. Pass translations on FloatingPanel to rename any of the four, and an aria-label on a button still wins over both.

Tab
Moves focus to the next focusable element. Focus isn't trapped inside the panel.
Shift+Tab
Moves focus to the previous focusable element.
Enter
On the trigger, opens or closes the panel. On a header button, minimizes, maximizes, restores or closes it.
Space
On the trigger, opens or closes the panel. On a header button, minimizes, maximizes, restores or closes it.
Arrow Left
When the panel itself has focus, moves it left by one pixel, or ten with Shift.
Arrow Right
When the panel itself has focus, moves it right by one pixel, or ten with Shift.
Arrow Up
When the panel itself has focus, moves it up by one pixel, or ten with Shift.
Arrow Down
When the panel itself has focus, moves it down by one pixel, or ten with Shift.
Alt+Arrow Left
When the panel itself has focus, narrows it by one pixel from its right edge, or ten with Shift.
Alt+Arrow Right
When the panel itself has focus, widens it by one pixel at its right edge, or ten with Shift.
Alt+Arrow Up
When the panel itself has focus, shortens it by one pixel from its bottom edge, or ten with Shift.
Alt+Arrow Down
When the panel itself has focus, makes it one pixel taller at its bottom edge, or ten with Shift.
Escape
Closes the topmost panel when closeOnEscape is set on FloatingPanel, even with focus outside it. During a drag or a resize, puts the panel back as it was when it started.

Demos

Controlled position

The panel's position lives in state, filled by the position-change event when the panel opens and again when a drag of the header ends. The body prints x and y, and four arrow buttons inside the panel move it 20 pixels at a time. Control the position when something else on the page moves the panel, or when you save where people left it.

Preview width

Controlled size

size lives in state, starting at 360 by 200, and dragging an edge writes the new size back through the size-change event. Shrink and Grow at the top of the panel change it by 50 by 40, and the readout follows. minSize stops a drag at 240 by 160 but doesn't clamp a size you pass in, so the Shrink handler clamps to the same floor.

Preview width

Custom spacing

The font settings panel from the top of the page, with its padding changed in one place. FloatingPanelContent sets --space, which the header, body and footer all read, and this one uses --spacing(3) on a phone and --spacing(6) from the sm breakpoint up. Change that variable instead of padding each part, so the three keep the same inset.

Preview width

Inside a container

A layers panel for a page editor that stays inside the dashed canvas around it. allowOverflow is false and getBoundaryEl returns the canvas element, so the panel opens centered in it, a drag stops at its edges, and Maximize fills the canvas rather than the window. Reach for it when a tool belongs to one region of the page.

Preview width

FAQ

When should I use a Floating Panel instead of a Dialog or a Popover?

Use a Floating Panel for a tool people keep open while they work on the page: an inspector, a layer list, a chat or a set of notes. It stays until they close it, a click outside doesn't dismiss it, and they can move it out of the way.

A Dialog blocks the page until its task is done or canceled. A Popover is pinned to the button that opened it and closes on a click outside, which suits a quick edit. On a phone, a Sheet from the edge of the screen fits better than a window people have to drag.

How do I control a Floating Panel's position in Vue?

Keep the position in a ref and bind it with v-model:position on FloatingPanel, which writes x and y back on opening while there's no position yet, on each arrow key that moves the panel, and once when a drag ends, since the panel follows the pointer on its own until then. The position-change-end event fires only for the drag, which is the moment to save it.

Without a position, the panel opens centered in the window. defaultPosition sets where it first appears, and getAnchorPosition computes the spot from the trigger's rect, for a panel that opens next to its button.

How do I control the size of a Floating Panel?

Keep the size in a ref and bind it with v-model:size on FloatingPanel, which writes width and height back as people resize, as the Controlled size demo does.

When you only care about the first size, set defaultSize. Without it the panel opens at 320 by 240. minSize and maxSize bound what a drag can reach, and lockAspectRatio keeps the proportions while resizing.

How do I open a Floating Panel from state in Vue?

Bind a ref with v-model:open on FloatingPanel, which writes the next state back when the trigger, the close button or Escape changes it.

A panel that keeps its own open state goes back to its starting size and position when it closes. Add persistRect to reopen it where people left it.

A closed panel's content also leaves the DOM, so fields inside start over each time it opens. Set lazyMount and unmountOnExit to false to keep them.

How do I minimize or maximize a Floating Panel?

Put FloatingPanelMinimize, FloatingPanelMaximize and FloatingPanelRestore in FloatingPanelControl inside the header. The first two hide while the panel is minimized or maximized, and Restore shows only then. A double-click on the header also maximizes the panel, or restores it.

Each change is reported by the stage-change event on FloatingPanel, and the content carries data-minimized, data-maximized and data-staged for styling. Setting resizable to false on FloatingPanel turns off resizing and staging together: the edge handles and the three buttons leave the panel, and a double-click on the header does nothing. To drop only the edge handles, set it to false on FloatingPanelContent instead.

Why doesn't Escape close my Floating Panel?

This component leaves it open unless you set closeOnEscape on FloatingPanel. A panel is often a tool people keep beside their work, so closing it by accident would lose their place.

With the option on, Escape closes the panel while it's the topmost layer on the page, even when focus is outside it. A click outside never closes it, so give it a close button, as the demos do.

How do I keep a Floating Panel inside the window or a container?

Set allowOverflow to false on FloatingPanel. As it ships, a drag can carry the panel past the left, right and bottom edges of the window, though never above the top.

To bound it by an element instead of the window, also pass getBoundaryEl a function that returns that element, such as the canvas of an editor. With allowOverflow off, the panel then opens centered in that element and stays inside its rect while people drag and resize it, as the Inside a container demo shows.

How do I change the padding inside a Floating Panel?

Set the --space variable on FloatingPanelContent, as the Custom spacing demo does. The header, body and footer all read it for their padding, and it starts at --spacing(4).

Changing that one value keeps the three parts in line, where padding each part yourself leaves them uneven. The window's own place and size are inline left, top, width and height on FloatingPanelContent, which the panel sets as it moves.

API Reference

FloatingPanel

PropType
open?boolean

Whether it's open. Pair with onOpenChange to control it. Two-way with v-model or v-model:open.

defaultOpen?boolean

Whether it starts open, when you don't control open.

Default
false
position?object

The controlled position of the panel. Two-way with v-model:position.

Type
{ x: number; y: number }
defaultPosition?object

The initial position of the panel when rendered. Use when you don't need to control the position of the panel.

Type
{ x: number; y: number }
size?object

The size. Two-way with v-model:size.

Type
{ height: number; width: number }
defaultSize?object

The default size of the panel.

Type
{ height: number; width: number }
allowOverflow?boolean

Whether the panel should be strictly contained within the boundary when dragging.

Default
true
closeOnEscape?boolean

Whether the panel should close when the escape key is pressed.

disabled?boolean

Whether it's disabled.

draggable?boolean

Whether the panel is draggable.

Default
true
finalFocusEl?() → HTMLElement | null

Element to receive focus when the panel is closed. By default, the trigger element is focused.

Type
() → HTMLElement | null
Returns
HTMLElement | null
getAnchorPosition?(details: { boundaryRect: DOMRect | null; triggerRect: DOMRect | null; }) → FloatingPanelPoint

Function that returns the initial position of the panel when it is opened. If provided, will be used instead of the default position.

Type
(details: { boundaryRect: DOMRect | null; triggerRect: DOMRect | null; }) → FloatingPanelPoint
Parameters

details – { boundaryRect: DOMRect | null; triggerRect: DOMRect | null; }

Returns
FloatingPanelPoint
getBoundaryEl?() → HTMLElement | null

The boundary of the panel. Useful for recalculating the boundary rect when. The it is resized.

Type
() → HTMLElement | null
Returns
HTMLElement | null
gridSize?number

The snap grid for the panel.

Default
1
initialFocusEl?() → HTMLElement | null | false

Element to receive focus when the panel is opened. By default, the first focusable element in the content is focused.

Type
() → HTMLElement | null | false
Returns
HTMLElement | null | false
lazyMount?boolean

Whether to enable lazy mounting.

Default
true
lockAspectRatio?boolean

Whether the panel is locked to its aspect ratio.

maxSize?object

The maximum size of the panel.

Type
{ height: number; width: number }
minSize?object

The minimum size of the panel.

Type
{ height: number; width: number }
persistRect?boolean

Whether the panel size and position should be preserved when it is closed.

resizable?boolean

Whether the panel is resizable.

Default
true
restoreFocus?boolean

Whether to restore focus to the trigger when the panel is closed.

Default
true
translations?object

The buttons' accessible names: the stage triggers' and, on this base, the close trigger's (close, "Close" by default).

Type
{ close?: string; maximize?: string; minimize?: string; restore?: string }
unmountOnExit?boolean

Whether to unmount on exit.

Default
true
EventType
@open-change( details: { open: boolean }, change: ChangeDetails<OpenReason> ) → void

Called when it opens or closes.

Type
( details: { open: boolean }, change: ChangeDetails<OpenReason> ) → void
Parameters

details – { open: boolean }

change – ChangeDetails<OpenReason>

Returns
void
@position-change( details: { position: FloatingPanelPoint }, change: ChangeDetails<BoxReason> ) → void

Function called when the position of the panel changes via dragging.

Type
( details: { position: FloatingPanelPoint }, change: ChangeDetails<BoxReason> ) → void
Parameters

details – { position: FloatingPanelPoint }

change – ChangeDetails<BoxReason>

Returns
void
@size-change( details: { size: FloatingPanelSize }, change: ChangeDetails<BoxReason> ) → void

Function called when the size of the panel changes via resizing.

Type
( details: { size: FloatingPanelSize }, change: ChangeDetails<BoxReason> ) → void
Parameters

details – { size: FloatingPanelSize }

change – ChangeDetails<BoxReason>

Returns
void
@position-change-end( details: { position: FloatingPanelPoint }, change: ChangeDetails<BoxReason> ) → void

Function called when the position of the panel changes via dragging ends.

Type
( details: { position: FloatingPanelPoint }, change: ChangeDetails<BoxReason> ) → void
Parameters

details – { position: FloatingPanelPoint }

change – ChangeDetails<BoxReason>

Returns
void
@size-change-end( details: { size: FloatingPanelSize }, change: ChangeDetails<BoxReason> ) → void

Function called when the size of the panel changes via resizing ends.

Type
( details: { size: FloatingPanelSize }, change: ChangeDetails<BoxReason> ) → void
Parameters

details – { size: FloatingPanelSize }

change – ChangeDetails<BoxReason>

Returns
void
@stage-change( details: { stage: FloatingPanelStage }, change: ChangeDetails<StageReason> ) → void

Function called when the stage of the panel changes.

Type
( details: { stage: FloatingPanelStage }, change: ChangeDetails<StageReason> ) → void
Parameters

details – { stage: FloatingPanelStage }

change – ChangeDetails<StageReason>

Returns
void

FloatingPanelTrigger

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

FloatingPanelContent

PropType
resizable?boolean

Enable resizable panel. When unset, it follows resizable on FloatingPanel.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

FloatingPanelDragTrigger

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

FloatingPanelHeader

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

CSS variableType
--spacestring

FloatingPanelControl

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

FloatingPanelStageTrigger

PropType
stageFloatingPanelStage

The stage of the panel.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

FloatingPanelMinimize

FloatingPanelMaximize

FloatingPanelRestore

PropType
class?string

Merged with the part's classes.

FloatingPanelTitle

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

FloatingPanelResizeTrigger

PropType
axisFloatingPanelResizeAxis

The axis of the resize handle.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

FloatingPanelCloseTrigger

<div> data-slot="scroll-area-scrollbar"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-dragging?string

Present while the thumb is dragged.

data-hovering?string

Present while a mouse or pen is over the scroll area.

data-orientation"vertical" | "horizontal"

The axis the scrollbar scrolls.

Type
"vertical" | "horizontal"
data-overflow-y?string

Present while the content is taller than the viewport.

data-scrolling?string

Present while its own axis scrolls.

data-visible?string

Present while the scrollbar should show, by type. Hidden scrollbars let presses through.

CSS variableType
--fade-sizestring
--scroll-area-thumb-heightstring

On a vertical scrollbar: its thumb's length in pixels. The thumb's inline height reads it.

--scroll-area-thumb-offsetstring

How far its thumb sits from the track's start, in pixels, negative right to left. The thumb's inline transform reads it.

--scroll-area-thumb-widthstring

On a horizontal scrollbar: its thumb's length in pixels. The thumb's inline width reads it.

FloatingPanelBody

PropType
scrollFade?boolean

Add a fade effect to the scroll area.

Default
false
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

CSS variableType
--spacestring

FloatingPanelFooter

<div> data-slot="floating-panel-footer"

PropType
class?string

Merged with the part's classes.

CSS variableType
--spacestring

useFloatingPanel