Back to Hooks

useTextSelection

packages/hooks/src/useTextSelection/index.en-US.md

3.9.71.5 KB
Original Source

useTextSelection

Tracking content, size, position of user text selection.

Examples

Default usage

<code src="./demo/demo1.tsx" />

Listen for specified area

<code src="./demo/demo3.tsx" />

Translate user text selection

<code src="./demo/demo2.tsx" />

API

typescript
const state = useTextSelection(target?);

Params

PropertyDescriptionTypeDefault
targetDOM element or refElement | Document | (() => Element\Document) | MutableRefObject<Element>document

Result

PropertyDescriptionType
stateContent, size, position of user text selectionState

State

PropertyDescriptionType
textSelected textstring
leftThe left coordinate value of textnumber
rightThe right coordinate value of textnumber
topThe top coordinate value of textnumber
bottomThe bottom coordinate value of textnumber
heightThe height of textnumber
widthThe width of textnumber