FloatingWindow
Draggable floating area
Source
LLM docs
Docs
Package
Usage
FloatingWindow creates a draggable element with a fixed position:
Constrain to viewport
Use the constrainToViewport prop to restrict element movement to the viewport boundaries.
If you do not set the constrainToViewport prop, the element can be dragged outside the viewport:
Constrain offset
Use the constrainOffset prop to set the offset from the viewport edges when constraining the element:
Drag handle selector
The dragHandleSelector prop allows specifying a selector of an element (or a group of elements) that should be used to drag the floating window.
If not specified, the entire root element is used as a drag target.
The excludeDragHandleSelector prop excludes elements within dragHandleSelector from the drag event.
In the following example, the close button is excluded from the drag event:
Enabled prop
Use the enabled option to enable or disable dragging:
Set position
Call the setPosition function to set the position of the element programmatically.
This function accepts an object with top, left, right and bottom properties,
from which you should only specify two (for example, top and left, bottom and right).
Resize handle
Use FloatingWindow.ResizeHandle compound component to add a resize handle to the floating window.
The dimensions prop on FloatingWindow controls the resize behavior:
initialWidth/initialHeight– initial size of the window in pxminWidth/minHeight– minimum size the window can be resized tomaxWidth/maxHeight– maximum size the window can be resized to
The resize handle respects constrainToViewport and constrainOffset props – the window
cannot be resized beyond the viewport boundaries.
FloatingWindow.ResizeHandle renders with role="separator" and supports keyboard interaction:
use Arrow Left/Arrow Right keys to resize width and Arrow Up/Arrow Down keys to resize
height in 10px steps. Home/End keys jump to the minimum/maximum size.
Lock axis
Use the axis option to restrict movement to the specified axis:
use-floating-window hook
If you prefer the hook API, you can use the useFloatingWindow hook.
It supports most of the FloatingWindow features: