Skip to content

Conversation

hadnet
Copy link

@hadnet hadnet commented Sep 6, 2025

Description

This PR introduces a new hook: useTextSelection.

The hook allows developers to easily access information about the current text selection inside the document (or optionally within a given target element). It provides:

  • clientRect: the bounding rectangle of the selection.
  • isCollapsed: whether the selection is collapsed or not.
  • textContent: the selected text content.

This hook can be useful for building rich text editors, annotation tools, tooltips, and context-aware UIs that need to react to user text selection.

It fits the sensors category, since it exposes live environmental data from the DOM, similar to hooks like useMouse or useHover.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas
  • Add documentation
  • Add hook's story at Storybook
  • Cover changes with tests
  • Ensure the test suite passes (yarn test)
  • Provide 100% tests coverage
  • Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
  • Make sure types are fine (yarn lint:types).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant