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
ThegetElementAtPosition() function uses document.elementsFromPoint() to find all elements at the cursor:
Valid Element Criteria
Elements must pass several checks to be selectable: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:- Click starts the drag at
(startX, startY) - Drag updates the rectangle continuously
- 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:- Creates a grid of sample points within the drag rectangle
- Tests each point to find the element underneath
- Counts hits for each unique element
- Filters elements that meet the coverage threshold (75% of samples)
Drag Preview
During drag, preview boxes show which elements will be selected: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):Visual States
The selection box has different visual states: Hover State (default):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
Navigation History
Copy Workflow
Single Element Copy
- Hover over element → selection box appears
- Press Enter or Click → copy starts
- Label shows “copying” status → API call in progress
- Label shows “copied” status → success feedback
- Grabbed box flashes briefly → visual confirmation
Multi-Element Copy
- Click and drag → drag box appears
- Preview boxes show selected elements
- Release mouse → selection freezes
- Label shows count (e.g., “3 elements”)
- Press Enter or Click → copy all
- Multiple grabbed boxes flash → all copied
