Skip to content

feat(useMouse): opt-in respectClipping to hit children outside their parent - #98

Merged
chiefcll merged 1 commit into
mainfrom
feat/usemouse-respect-clipping
Nov 25, 2026
Merged

chiefcll merged 1 commit into
mainfrom
feat/usemouse-respect-clipping

Conversation

@chiefcll

Copy link
Copy Markdown
Contributor

What

Adds an opt-in respectClipping option to useMouse:

useMouse(App, 100, { respectClipping: true });

Why

Reported from an LG app: elements drawn outside their parent's bounds (parent with clipping: false, the renderer default) render fine but can't be hovered or clicked with the Magic Remote. The hit test in getChildrenByPosition only descends into a child the pointer is inside, so it treats every node as if it clipped.

How

  • UseMouseOptions gains respectClipping?: boolean. customStates is now optional, so { respectClipping: true } works alone; every previously valid shape still type-checks.
  • With the flag on, a new collectHitPath DFS runs instead of the single-path loop:
    • prunes a subtree only where the missed node has clipping set
    • pushes only nodes the pointer is actually over (ancestors first), so the "deepest focusable" and forwardStates logic downstream is unchanged
    • visits children topmost-first: higher zIndex, then later sibling (same tie rule as today), with an explicit index tiebreak because old webOS engines don't have a stable Array.prototype.sort
    • still skips alpha: 0 and skipFocus subtrees
  • Flag threads through hover, click and mousedown. With it off, the existing search runs untouched.

Reviewer notes

  • Perf: most nodes don't clip, so with the flag on each throttled pointer move searches most of the tree rather than one path. That's why it's opt-in; it hasn't been measured on LG hardware yet. If it proves cheap enough, it could become the default later.
  • findElementByActiveElement (click without customStates) only tests the active element and its ancestors against their own boxes, so it needed no change.
  • A <view> with no width/height fills its parent, so size-less wrappers were never part of this bug.

Tests

Five new tests in tests/useMouse.test.tsx (useMouse respectClipping): default still misses an overflowing child; flag on hits it; a clipping parent still blocks; hover + click reach an overflowing child via customStates; a higher-z sibling's overflow beats a lower sibling. Full suite: 772 passed, tsc and lint clean.

🤖 Generated with Claude Code

…parent

The mouse hit test stops descending at any node the pointer misses, so a
child drawn outside a non-clipping parent (clipping is off by default in
the renderer) can't be hovered or clicked with the LG Magic Remote.

With `respectClipping: true`, a subtree is cut off only where a node sets
`clipping`; the search otherwise keeps descending, recording only nodes
the pointer is over. Topmost wins by zIndex, then later sibling, with an
index tiebreak since old webOS engines lack a stable sort. Off by default,
so the existing single-path search is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chiefcll
chiefcll merged commit fe393b6 into main Nov 25, 2026
1 check passed
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