Skip to content

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

Components

Free

Floating Panel for Solid

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

On this page9 sections
UI library: Ark UI

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

import { XIcon } from "lucide-solid";
import { Button } from "@/components/ui/button";
import {
  FloatingPanel, FloatingPanelBody, FloatingPanelCloseTrigger,
  FloatingPanelContent, FloatingPanelControl, FloatingPanelHeader,
  FloatingPanelMaximize, FloatingPanelMinimize, FloatingPanelRestore,
  FloatingPanelTitle, FloatingPanelTrigger,
} from "@/components/ui/floating-panel";

FloatingPanelHeader is the drag handle, and FloatingPanelContent adds the resize handles on every edge and corner.

<FloatingPanel defaultSize={{ width: 360, height: 240 }}>
  <FloatingPanelTrigger
    asChild={(props) => (
      <Button {...props()} variant="outline">Open notes</Button>
    )}
  />
  <FloatingPanelContent>
    <FloatingPanelHeader>
      <FloatingPanelTitle>Notes</FloatingPanelTitle>
      <FloatingPanelControl>
        <FloatingPanelMinimize />
        <FloatingPanelMaximize />
        <FloatingPanelRestore />
        <FloatingPanelCloseTrigger
          asChild={(props) => (
            <Button {...props()} aria-label="Close" size="icon-xs" variant="ghost">
              <XIcon aria-hidden />
            </Button>
          )}
        />
      </FloatingPanelControl>
    </FloatingPanelHeader>
    <FloatingPanelBody>
      <p>Drag the header to move this window, or pull an edge to resize it.</p>
    </FloatingPanelBody>
  </FloatingPanelContent>
</FloatingPanel>

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. Dragging and resizing need a pointer, but the arrow keys move the panel while it has focus. The minimize, maximize and restore buttons come with labels, and the close trigger reads Close Window unless you give it a label of your own.

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.
Escape
Closes the panel when closeOnEscape is set on FloatingPanel. 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 onPositionChange when the panel opens and again as you drag the header. 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 onSizeChange. 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 Solid?

Keep the position in state, pass it as position on FloatingPanel and update it in onPositionChange, which receives an object whose position holds x and y. The callback fires on every step of a drag, and on opening while there's no position yet. onPositionChangeEnd fires once when a drag ends, 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 state, pass it as size on FloatingPanel and update it in onSizeChange, which receives an object whose size holds width and height, 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 Solid?

Pass a boolean as open on FloatingPanel and update it in onOpenChange, which receives an object with the next state in open.

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 to onStageChange 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?

Ark UI 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 when focus is inside it and it's the topmost panel on the page. 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 come from --x, --y, --width and --height on the positioner, which the panel sets as it moves.

API Reference

FloatingPanel

data-slot="floating-panel"

PropType
open?boolean

The controlled open state of the panel.

defaultOpen?boolean

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

Default
false
onOpenChange?(details: OpenChangeDetails) → void

Function called when the panel is opened or closed.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
position?object

The controlled position of the panel.

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 }
onPositionChange?(details: PositionChangeDetails) → void

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

Type
(details: PositionChangeDetails) → void
Parameters

details – { position: Point }

Returns
void
size?object

The size of the panel.

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

The default size of the panel.

Type
{ width: number; height: number }
onSizeChange?(details: SizeChangeDetails) → void

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

Type
(details: SizeChangeDetails) → void
Parameters

details – { size: Size }

Returns
void
allowOverflow?boolean

Whether the panel should be strictly contained within the boundary when dragging. Ark default: true.

Default
!inPreview
closeOnEscape?boolean

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

dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
disabled?boolean

Whether the panel is 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: AnchorPositionDetails) → Point

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: AnchorPositionDetails) → Point
Parameters

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

Returns
Point
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
hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the floating panel. Useful for composition.

Type
{ trigger?: string; positioner?: string; content?: string; title?: string; header?: string }
immediate?boolean

Whether to synchronize the present change immediately or defer it to the next frame.

initialFocusEl?() → HTMLElement | null | false

Element to receive focus when the panel is opened. Defaults to the panel content. Return false to skip moving focus, or null to use the default.

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

Whether to enable lazy mounting. Ark default: false.

Default
true
lockAspectRatio?boolean

Whether the panel is locked to its aspect ratio.

maxSize?object

The maximum size of the panel.

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

The minimum size of the panel.

Type
{ width: number; height: number }
onEnterComplete?VoidFunction

Function called when the animation ends in the open state.

onExitComplete?VoidFunction

Function called when the animation ends in the closed state.

onPositionChangeEnd?(details: PositionChangeDetails) → void

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

Type
(details: PositionChangeDetails) → void
Parameters

details – { position: Point }

Returns
void
onSizeChangeEnd?(details: SizeChangeDetails) → void

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

Type
(details: SizeChangeDetails) → void
Parameters

details – { size: Size }

Returns
void
onStageChange?(details: StageChangeDetails) → void

Function called when the stage of the panel changes.

Type
(details: StageChangeDetails) → void
Parameters

details – { stage: Stage }

Returns
void
persistRect?boolean

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

present?boolean

Whether the node is present (controlled by the user).

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
skipAnimationOnMount?boolean

Whether to allow the initial presence animation.

Default
false
strategy?"absolute" | "fixed"

The strategy to use for positioning.

Type
"absolute" | "fixed"
Default
"fixed"
translations?object

The translations for the floating panel.

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

Whether to unmount on exit. Ark default: false.

Default
true

FloatingPanelTrigger

<button> data-slot="floating-panel-trigger"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-dragging?string

Present when in the dragging state.

data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"

FloatingPanelPositioner

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

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
CSS variableType
--heightstring

The height of the element.

--widthstring

The width of the element.

--xstring

The x position for transform.

--ystring

The y position for transform.

--z-indexstring

The z-index value.

FloatingPanelContent

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

PropType
resizable?boolean

Enable resizable panel. When unset, it follows resizable on FloatingPanel, since zag ignores the handles while that is false.

Default
true
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-behind?string

Present when not topmost.

data-dragging?string

Present when in the dragging state.

data-maximized?string

Present when maximized.

data-minimized?string

Present when minimized.

data-staged?string

Present when not in default stage.

data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
data-topmost?string

Present when topmost.

CSS variableType
--heightstring

The measured height, for animating open and closed.

--widthstring

The measured width, for animating open and closed.

--xstring

The horizontal position.

--ystring

The vertical position.

FloatingPanelHeader

<div>

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-behind?string

Present when not topmost.

data-dragging?string

Present when in the dragging state.

data-maximized?string

Present when maximized.

data-minimized?string

Present when minimized.

data-staged?string

Present when not in default stage.

data-topmost?string

Present when topmost.

CSS variableType
--spacestring

FloatingPanelBody

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

PropType
scrollFade?boolean

Add a fade effect to the scroll area.

Default
false
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-dragging?string

Present when in the dragging state.

data-maximized?string

Present when maximized.

data-minimized?string

Present when minimized.

data-staged?string

Present when not in default stage.

CSS variableType
--spacestring

FloatingPanelTitle

<h2> data-slot="floating-panel-title"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

FloatingPanelResizeTrigger

<div> data-slot="floating-panel-resize-trigger"

PropType
axis"s" | "w" | "e" | "n" | "sw" | "nw" | "se" | "ne"

The axis of the resize handle.

Type
"s" | "w" | "e" | "n" | "sw" | "nw" | "se" | "ne"
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-axisstring

Mirrors the axis prop.

data-disabled?string

Present when disabled.

data-placement?string

The placement of the resizetrigger.

FloatingPanelDragTrigger

<div> data-slot="floating-panel-drag-trigger"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-disabled?string

Present when disabled.

FloatingPanelStageTrigger

<button> data-slot="floating-panel-stage-trigger"

PropType
stage"minimized" | "maximized" | "default"

The stage of the panel.

Type
"minimized" | "maximized" | "default"
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-stagestring

The stage of the stagetrigger.

FloatingPanelCloseTrigger

<button> data-slot="floating-panel-close-trigger"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element

FloatingPanelControl

<div>

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-maximized?string

Present when maximized.

data-minimized?string

Present when minimized.

data-stagestring

The stage of the control.

data-staged?string

Present when not in default stage.

FloatingPanelMinimize

<button>

PropType
stage"minimized" | "maximized" | "default"

The stage of the panel.

Type
"minimized" | "maximized" | "default"
Default
minimized
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-stagestring

The stage of the stagetrigger.

FloatingPanelMaximize

<button>

PropType
stage"minimized" | "maximized" | "default"

The stage of the panel.

Type
"minimized" | "maximized" | "default"
Default
maximized
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-stagestring

The stage of the stagetrigger.

FloatingPanelRestore

<button>

PropType
clickEffect?boolean

Apply a click effect to the button.

Default
true
isLoading?boolean

Show a loading indicator.

Default
false
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-stagestring

The stage of the stagetrigger.

FloatingPanelFooter

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

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

CSS variableType
--spacestring

useFloatingPanel

PropType
open?boolean

The controlled open state of the panel.

defaultOpen?boolean

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

Default
false
onOpenChange?(details: OpenChangeDetails) → void

Function called when the panel is opened or closed.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
position?object

The controlled position of the panel.

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 }
onPositionChange?(details: PositionChangeDetails) → void

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

Type
(details: PositionChangeDetails) → void
Parameters

details – { position: Point }

Returns
void
size?object

The size of the panel.

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

The default size of the panel.

Type
{ width: number; height: number }
onSizeChange?(details: SizeChangeDetails) → void

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

Type
(details: SizeChangeDetails) → void
Parameters

details – { size: Size }

Returns
void
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.

dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
disabled?boolean

Whether the panel is 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: AnchorPositionDetails) → Point

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: AnchorPositionDetails) → Point
Parameters

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

Returns
Point
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
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the floating panel. Useful for composition.

Type
{ trigger?: string; positioner?: string; content?: string; title?: string; header?: string }
initialFocusEl?() → HTMLElement | null | false

Element to receive focus when the panel is opened. Defaults to the panel content. Return false to skip moving focus, or null to use the default.

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

Whether the panel is locked to its aspect ratio.

maxSize?object

The maximum size of the panel.

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

The minimum size of the panel.

Type
{ width: number; height: number }
onPositionChangeEnd?(details: PositionChangeDetails) → void

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

Type
(details: PositionChangeDetails) → void
Parameters

details – { position: Point }

Returns
void
onSizeChangeEnd?(details: SizeChangeDetails) → void

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

Type
(details: SizeChangeDetails) → void
Parameters

details – { size: Size }

Returns
void
onStageChange?(details: StageChangeDetails) → void

Function called when the stage of the panel changes.

Type
(details: StageChangeDetails) → void
Parameters

details – { stage: Stage }

Returns
void
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
strategy?"absolute" | "fixed"

The strategy to use for positioning.

Type
"absolute" | "fixed"
Default
"fixed"
translations?object

The translations for the floating panel.

Type
{ minimize?: string; maximize?: string; restore?: string }