Skip to content

useTextSelection

Hook that manages the text selection

sensors
low
test coverage
Last changed: 7 months ago

TIP

This hook uses document.getSelection browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

Installation

Library
CLI
Manual
typescript
import { useTextSelection } from '@siberiacancode/reactuse';

Usage

typescript
const selection = useTextSelection();

Demo

Api

Returns

UseTextSelectionReturn

Type declaration

typescript
export interface UseTextSelectionReturn {
  /** The current selection ranges */
  ranges: Range[];
  /** The current selection rects */
  rects: DOMRect[];
  /** The current selection */
  selection: Selection | null;
  /** The current selection text */
  text: string;
}

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.