Skip to main content

Overview

The SelectionBox component enables rectangle selection (also known as “marquee selection” or “lasso selection”) for selecting multiple blocks at once. When the user clicks and drags outside the editor area, a selection rectangle appears, and all blocks that intersect with this rectangle become selected.
Yoopta SelectionBox screenshot

Features

  • ✅ Rectangle selection for multiple blocks
  • ✅ Works outside the editor area
  • ✅ Automatic block selection based on intersection
  • ✅ Supports custom container element
  • ✅ Respects read-only mode
  • ✅ Lightweight and performant

Basic Usage

The selectionBoxElement should be a parent container that wraps the editor. The selection box will listen for mouse events on this element. It must NOT be a child of the editor itself.

API Reference

SelectionBox Component

The main component that renders the selection rectangle and handles mouse events.

Props

useRectangeSelectionBox Hook

For advanced use cases, you can use the hook directly to build custom selection UI.

Hook Parameters

Hook Return Value

Types

Examples

Basic Setup with Container Ref

Full Page Selection

For full-page selection support, pass a ref to the outermost container:

Without SelectionBox

If you don’t need rectangle selection, simply don’t include the component:

How It Works

  1. Mouse Down - When the user clicks outside the editor (but inside the container), the selection starts
  2. Mouse Move - As the user drags, the selection rectangle grows/shrinks
  3. Block Detection - Blocks that intersect with the selection rectangle are marked as selected
  4. Mouse Up - Selection ends, selected blocks remain highlighted
  5. Click Outside - Clicking outside clears the selection
The selected blocks can then be:
  • Copied (Ctrl/Cmd + C)
  • Cut (Ctrl/Cmd + X)
  • Deleted (Backspace or Delete)

Styling

The default selection box has a semi-transparent blue background:
To customize the appearance, use the useRectangeSelectionBox hook and build your own UI.

Best Practices

Always wrap your editor in a container element and pass that ref to SelectionBox. This ensures selection works in the area outside the editor content.
The container should NOT be a child of the editor. The SelectionBox needs to capture mouse events outside the editor content area.
Pass the ref object itself, not ref.current. This ensures the component can access the element even if it’s not mounted on the first render.

Accessibility

  • Selection box is purely visual and doesn’t affect screen readers
  • Selected blocks are still accessible via keyboard navigation
  • Use keyboard shortcuts (Ctrl/Cmd + A) for full selection as an alternative

FloatingBlockActions

Actions that appear when hovering over blocks

BlockOptions

Context menu for block operations