All components (283)
Floating window
Utilities · FloatingWindow
What it is and when to use it
A loose panel that moves around the screen without blocking what is behind: a player, a calculator, a help chat.
When to use it
- Something consulted while still working on the page.
openandonCloseopen and close it, andinitialPositionsays where it appears.
When not to
- What must be answered before continuing:
Dialog. - A panel stuck to one side:
Drawer.
Keyboard: Tab reaches the bar and, with it focused, the arrows move the window (with Shift, a bigger jump). The close button is next to it. Focus does not move by itself on opening: it is not modal.
Accessibility: it is a non-modal dialog, named by its title. It cannot be taken off the screen, neither by dragging nor by shrinking the browser window, so the bar stays within reach.
Fine-tuning: --amset-floatwin-width is the width.
What it looks like
<FloatingWindow
title="Order notes"
open={abierta}
onClose={() => setAbierta(false)}
initialPosition={{ x: 48, y: 120 }}
>
<p>Drag it by the title. What's behind it can still be used.</p>
</FloatingWindow>Props
Import it with import { FloatingWindow } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
childrenrequired | ReactNode | — |
onCloserequired | () => void | — |
openrequired | boolean | — |
titlerequired | string | What appears in the bar, and the name of the window. |
axis | "y" | "x" | Locks movement to one axis. |
className | string | Merged with the library classes; it does not replace them. |
closeOnEscape | boolean | Closes the window with Escape while focus is inside it. Defaults to yes. |
constrainOffset | number | Pixels left free between the window and the edge of the screen. Defaults to 0. |
draggable | boolean | Can be dragged. Defaults to yes. |
initialPosition | FloatingWindowPosition | Where it appears on opening, from the corner of the browser window. |
initialSize | FloatingWindowSize | — |
maxHeight | number | — |
maximizable | boolean | Shows the maximize button (the window fills the screen, and goes back). |
maxWidth | number | — |
minHeight | number | — |
minimizable | boolean | Shows the minimize button (collapses the window into its bar). |
minWidth | number | — |
onPositionChange | (position: FloatingWindowPosition) => void | Called every time the window moves, by dragging or with the keyboard. |
onResizeEnd | (size: FloatingWindowSize) => void | — |
onResizeStart | () => void | — |
onSizeChange | (size: FloatingWindowSize) => void | — |
resizable | boolean | Adds a handle in the corner to change the size, with the mouse and the keyboard. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
