Features
- Virtual floating elements that follow cursor position
- Floating toolbar that appears on text selection
- Built on top of Floating UI
- Customizable positioning and behavior
- Automatic updates on scroll and resize
Installation
pnpm add @platejs/floating
API Hooks
useVirtualFloating
Creates a floating element with a controlled virtual element, typically used to follow cursor position.
getBoundingClientRect optional () => ClientRectObject
Function to get the bounding client rect.
- Default: Returns a zero-sized rect at (0,0)
open optional boolean
Controls visibility of the floating element.
whileElementsMounted optional function
Callback when elements are mounted.
- Default:
autoUpdate
(updates on scroll and resize)
- Default:
useFloatingToolbar
Creates a floating toolbar that appears when text is selected in the editor.
API
getBoundingClientRect
Gets the bounding client rectangle for a location or array of locations in the editor.
getDOMSelectionBoundingClientRect
getRangeBoundingClientRect
Gets the bounding client rectangle for a specific Plate range.
getSelectionBoundingClientRect
Gets the bounding client rectangle of the current editor selection.