Frontendx
README.md
SOLUTION.md
main.tsxentry
App.tsx
App.css
index.html
vite.config.ts
Installed
react@^19.2.0
react-dom@^19.2.0

Highlight Text on Selection in React

Prompt

When a user selects/highlights any text on the page show a floating tooltip or toolbar above the selection (like Medium's highlight toolbar). Use the Selection API to get selected text and its bounding rect. Display action buttons (copy, share, highlight) in the tooltip.

Listen to mouseup event on document. Call window.getSelection() to get selected text. If not empty call selection.getRangeAt(0).getBoundingClientRect() to get position. Position tooltip absolutely using rect.top + window.scrollY. Hide on mousedown.
Test Results

Highlight Text on Selection in React

When a user selects/highlights any text on the page show a floating tooltip or toolbar above the selection (like Medium's highlight toolbar). Use the Selection API to get selected text and its bounding rect. Display action buttons (copy, share, highlight) in the tooltip.