Skip to main content

Overview

React Grab provides precise element selection with real-time visual feedback. You can select single elements by hovering, or multiple elements by dragging.

Single Element Selection

Hover Detection

When activated, React Grab continuously tracks your cursor position to detect the element underneath:

Element Position Detection

The getElementAtPosition() function uses document.elementsFromPoint() to find all elements at the cursor:

Valid Element Criteria

Elements must pass several checks to be selectable:
Root elements that are filtered out:

Ignoring Elements

You can mark elements to be ignored:

Detection Throttling

To optimize performance, element detection is throttled:

Multi-Element Selection

Drag Selection

Click and drag to select multiple elements within a rectangular area:
  1. Click starts the drag at (startX, startY)
  2. Drag updates the rectangle continuously
  3. Release finalizes the selection

Drag State Management

Drag Threshold

Small movements don’t trigger drag mode:

Rectangle Calculation

Element Detection Within Drag

React Grab samples points within the drag rectangle to find intersecting elements:
This algorithm:
  1. Creates a grid of sample points within the drag rectangle
  2. Tests each point to find the element underneath
  3. Counts hits for each unique element
  4. Filters elements that meet the coverage threshold (75% of samples)

Drag Preview

During drag, preview boxes show which elements will be selected:
The preview is debounced to avoid excessive calculations during rapid mouse movement.

Visual Feedback System

Selection Box

Highlights the currently hovered element:

Bounds Calculation

Accurately calculates element bounds including transforms:

Transform Handling

For elements with CSS transforms, React Grab walks up the ancestor tree:

Smooth Interpolation

Selection boxes smoothly follow the cursor using linear interpolation (lerp):
This creates a smooth trailing effect rather than instant snapping.

Visual States

The selection box has different visual states: Hover State (default):
Drag State:
Frozen State (after selection):

Grabbed Boxes

Brief flash effects after successful copy:

Element Labels

Floating labels display component information:

Label Positioning

Labels intelligently position above or below elements:

Arrow Positioning

Labels have arrows that point to the element, positioned based on cursor location:

Keyboard Navigation

When an element is selected, use arrow keys to navigate:

Arrow Key Navigation

  • ↑ Up: Select parent element
  • ↓ Down: Select first child element
  • ← Left: Select previous sibling
  • → Right: Select next sibling

Copy Workflow

Single Element Copy

  1. Hover over element → selection box appears
  2. Press Enter or Click → copy starts
  3. Label shows “copying” status → API call in progress
  4. Label shows “copied” status → success feedback
  5. Grabbed box flashes briefly → visual confirmation

Multi-Element Copy

  1. Click and drag → drag box appears
  2. Preview boxes show selected elements
  3. Release mouse → selection freezes
  4. Label shows count (e.g., “3 elements”)
  5. Press Enter or Click → copy all
  6. Multiple grabbed boxes flash → all copied

Performance Considerations

Bounds Caching

Bounds Revalidation

Periodically revalidate bounds for scroll/resize:

Viewport Version Tracking

Invalidate bounds on scroll/resize: