Floating panel
A non-modal card that floats above the page and can be dragged anywhere on screen: notes, help, inspectors, chat.
Example
Drag me by the header, or use the move button and the arrow keys.
<focsd-button id="notes-open">Notes</focsd-button><focsd-floating-panel label="Notes" trigger="notes-open"> <p>Drag me by the header, or use the move button and the arrow keys.</p> <focsd-textarea label="Note"></focsd-textarea></focsd-floating-panel>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-floating-panel.js';</script>
<focsd-floating-panel label="Notes" trigger="notes-open">…</focsd-floating-panel>import { FloatingPanel } from '@focsd-dev/react';
export function Example() { return <FloatingPanel onClose={(e) => console.log(e.target)} label="Notes" trigger="notes-open">…</FloatingPanel>;}<script setup>import '@focsd-dev/components/focsd-floating-panel.js';</script>
<template> <focsd-floating-panel @close="onChange" label="Notes" trigger="notes-open">…</focsd-floating-panel></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-floating-panel.js';
// template<focsd-floating-panel (close)="onChange($event)" label="Notes" trigger="notes-open">…</focsd-floating-panel><script> import '@focsd-dev/components/focsd-floating-panel.js';</script>
<focsd-floating-panel onclose={(e) => console.log(e.target)} label="Notes" trigger="notes-open">…</focsd-floating-panel>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
open | open | boolean | false |
trigger | trigger | string | — |
Methods
| Method | Description |
|---|---|
show() | Open the panel and move focus into it. |
close() | Close the panel; focus returns to the trigger (or the element focused before opening). |
moveTo(x, y) | Move the panel to (x, y) CSS pixels from the top left of the viewport, kept on screen. |
Events
| Event | Description |
|---|---|
close | Fired after the panel closes. Like <dialog>, it does not bubble. |
Slots
| Slot | Description |
|---|---|
(default) | The panel content. |
CSS parts
Style the inside of the component with ::part(), for example focsd-floating-panel::part(panel).
| Part | Description |
|---|---|
panel | The floating panel (role="dialog"). |
header | The draggable header. |
title | The title. |
move-handle | The move button (arrow keys move the panel). |
close | The close button. |
body | The content area. |
Accessibility
- A non-modal
role="dialog"named bylabel; the page stays usable while it is open, and the trigger getsaria-expanded. - Dragging has a keyboard alternative (WCAG 2.5.7): the move button moves the panel with the arrow keys.
- The panel always stays fully on screen, including when the window is resized, and remembers where it was moved.
- Several panels can be open at once; the one you click or focus comes to the front.
Keyboard
| Key | Action |
|---|---|
| Enter / Space (trigger) | Open or close |
| Arrow keys (move button) | Move 10px |
| Shift + arrow keys (move button) | Move 50px |
| Escape | Close and return focus to the trigger |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.