shadcn-ahooks

useTextSelection

Tracking content, size, position of user text selection.

Overview

Tracking content, size, position of user text selection.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTextSelection.json

Tracking content, size, position of user text selection.

Examples

Default usage

Listen for specified area

Translate user text selection

API

const state = useTextSelection(target?);

Params

| Property | Description | Type | Default | | -- | | | - | - | | state | Content, size, position of user text selection | State |

State

| Property | Description | Type | | -- | ----- | | text | Selected text | string | | left | The left coordinate value of text | number | | right | The right coordinate value of text | number | | top | The top coordinate value of text | number | | bottom | The bottom coordinate value of text | number | | height | The height of text | number | | width | The width of text | number |

On this page