Skip to content
EspañolEnglish
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.
  • open and onClose open and close it, and initialPosition says 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.

PropTypeWhat it does
childrenrequiredReactNode—
onCloserequired() => void—
openrequiredboolean—
titlerequiredstringWhat appears in the bar, and the name of the window.
axis"y" | "x"Locks movement to one axis.
classNamestringMerged with the library classes; it does not replace them.
closeOnEscapebooleanCloses the window with Escape while focus is inside it. Defaults to yes.
constrainOffsetnumberPixels left free between the window and the edge of the screen. Defaults to 0.
draggablebooleanCan be dragged. Defaults to yes.
initialPositionFloatingWindowPositionWhere it appears on opening, from the corner of the browser window.
initialSizeFloatingWindowSize—
maxHeightnumber—
maximizablebooleanShows the maximize button (the window fills the screen, and goes back).
maxWidthnumber—
minHeightnumber—
minimizablebooleanShows the minimize button (collapses the window into its bar).
minWidthnumber—
onPositionChange(position: FloatingWindowPosition) => voidCalled every time the window moves, by dragging or with the keyboard.
onResizeEnd(size: FloatingWindowSize) => void—
onResizeStart() => void—
onSizeChange(size: FloatingWindowSize) => void—
resizablebooleanAdds 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: