Interaction
When the popover appears and what hides it.
Showing the popover
When the user selects with a mouse or pen, the popover appears after they release it. Set showWhileSelecting to show and update the popover during the drag instead.
showWhileSelecting=false
Drag slowly across this sentence and watch when the popover appears.
showWhileSelecting=true
Drag slowly across this sentence and watch when the popover appears.
Keyboard selections show the popover immediately. minSelectionLength sets the minimum number of characters, not counting whitespace at either end.
Interacting with the popover
Clicking inside the popover keeps it open, so its buttons work even when the click clears the selection. Selecting text inside the popover doesn't move it.
Dismissing the popover
The popover hides when the selection becomes empty or moves outside the wrapper.
Pressing Escape also hides it, until the selection changes. Set closeOnEscape={false} to turn this off.
Controlling the popover
setShowPopover from useHighlightPopover shows or hides the popover. Hiding it works like Escape, so the popover stays hidden until the selection changes.
function Popover() {
const { setShowPopover } = useHighlightPopover();
return <button onClick={() => setShowPopover(false)}>Done</button>;
}Callbacks
| Callback | Fires when |
|---|---|
onSelectionStart | A selection begins inside the wrapper |
onSelectionEnd | A selection is complete. Receives the selected text |
onPopoverShow | The popover appears |
onPopoverHide | The popover is hidden, including on unmount |
Callbacks can be inline functions. The component always calls the latest version, and a new function on each render doesn't fire extra callbacks.