apps/mantine.dev/src/pages/core/floating-window.mdx
import { FloatingWindowDemos, UseFloatingWindowDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.FloatingWindow);
FloatingWindow creates a draggable element with a fixed position:
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:
Use the constrainOffset prop to set the offset from the viewport edges when constraining the element:
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:
Use the enabled option to enable or disable dragging:
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).
Use the axis option to restrict movement to the specified axis:
If you prefer the hook API, you can use the useFloatingWindow hook.
It supports most of the FloatingWindow features: