Skip to content

fix: scope iOS selection allow to the locked element so handles drag in any direction#161

Open
hirbod wants to merge 1 commit into
theKashey:masterfrom
hirbod:ios-selection-lock-ref-scope
Open

fix: scope iOS selection allow to the locked element so handles drag in any direction#161
hirbod wants to merge 1 commit into
theKashey:masterfrom
hirbod:ios-selection-lock-ref-scope

Conversation

@hirbod
Copy link
Copy Markdown

@hirbod hirbod commented May 9, 2026

What

Follow-up to #144. The current iOS selection allowance only skips preventDefault when the touchmove target is inside selection.anchorNode. On iOS Safari (tested on 26.4.2) that check fails for several common cases inside Radix Dialog / similar lock-scroll modals:

  • Extending the selection backward (anchor stays put, handle moves into a region that isn't a descendant of anchorNode).
  • Dragging the handle into a sibling element such as a dialog title above the original selected paragraph.
  • iOS reporting touchmove targets that don't sit inside anchorNode even when the user is clearly mid-gesture.

The result: handles get stuck after the initial long-press and the user can't re-select.

How

Key the allowance off the locked element instead. If there's an active non-collapsed selection AND the touch target is inside lastProps.current.lockRef.current, skip preventDefault. Touches outside the locked element still hit the normal scroll-lock path, so body scroll lock keeps working.

This is a strict superset of the existing behavior for any selection that's actually inside the locked element, which is the only case that matters for the iOS bug.

Verification

  • Local Storybook works as before; existing tests pass (yarn test).
  • Verified end-to-end against iOS 26.4.2 Safari in a Radix Dialog: selection handles drag forward, backward, and across element boundaries (e.g. title <-> body) without releasing the body scroll lock outside the dialog.

Refs radix-ui/primitives#3331.

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