Skip to content

Update Pressable props - #4421

Merged
m-bert merged 1 commit into
mainfrom
@mbert/pressable-testonly-hover
Aug 14, 2026
Merged

Update Pressable props#4421
m-bert merged 1 commit into
mainfrom
@mbert/pressable-testonly-hover

Conversation

@m-bert

@m-bert m-bert commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Description

Follow-up to #4416. None of the Pressable engines forwarded hover handlers as testOnly_* props, so fireEvent(element, 'hoverIn') from React Native Testing Library had no way to reach onHoverIn/onHoverOut. RNTL resolves testOnly_on{EventName} generically for any event, so exposing the props is all that's needed.

This adds testOnly_onHoverIn/testOnly_onHoverOut to the button props and forwards them, guarded by isTestEnv(), from all three engines: legacy Pressable, StatefulPressable and PressableWithTouchable.

Also widens the relation props (simultaneousWith/requireToFail/block) from AnyGesture to AnyGesture | AnyGesture[]. The JSDoc already promises a gesture object or an array of gesture objects and the runtime handles arrays in both directions (relationUtils flattens them into handler tags and pushes the symmetric relation onto each array element), only the prop type was narrowed.

Test plan

Added tests in src/__tests__/mocks.test.tsx asserting the hover props are wired on the button for both v3 engines — relation-free and routed to StatefulPressable via simultaneousWith={[]} (which the type widening makes legal). Both fail without the engine changes.

In packages/react-native-gesture-handler: yarn test, yarn ts-check and yarn lint:js pass.

Copilot AI lite review requested due to automatic review settings August 14, 2026 08:43
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8658983d-9346-4aca-a837-2f442f2dcc89

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc2dec and 3b3f012.

📒 Files selected for processing (7)
  • packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
  • packages/react-native-gesture-handler/src/components/GestureButtonsProps.ts
  • packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx
  • packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx
  • packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx
  • packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx
  • packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Pressable gesture relationships now support configuring multiple gestures for simultaneous recognition, failure requirements, and blocking.
    • Added hover callback support for testing Pressable and Touchable interactions.
  • Bug Fixes

    • Improved test-environment forwarding of press, long-press, and hover handlers across Pressable components.
  • Tests

    • Added coverage verifying press and hover callbacks are correctly forwarded during testing.

Walkthrough

Pressable test-only props now forward hover callbacks across default and v3 implementations. Button prop types include hover compatibility fields. Gesture relation props accept single gestures or arrays. Tests cover default and relation-based engines.

Changes

Pressable testing compatibility

Layer / File(s) Summary
Button and gesture relation contracts
packages/react-native-gesture-handler/src/components/GestureButtonsProps.ts, packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx, packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx
Button props now include test-only hover callbacks. Pressable gesture relation props accept one gesture or an array.
Default Pressable forwarding
packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx, packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
The default Pressable forwards long-press and hover callbacks through testOnly_* props. Tests verify hover forwarding.
v3 Pressable callback forwarding
packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx, packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx, packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
v3 Pressable components forward hover callbacks in test environments. Tests cover press and hover forwarding for relation-based StatefulPressable.

Sequence Diagram(s)

sequenceDiagram
  participant TestingLibrary
  participant StatefulPressable
  participant NativeButton
  TestingLibrary->>StatefulPressable: Render press and hover handlers
  StatefulPressable->>NativeButton: Forward testOnly_* callbacks
  NativeButton->>TestingLibrary: Expose rendered callbacks
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: j-piasecki

Merge Risk: ⚪ Minimal · up to 3b3f0

The change enables hover-event testing across Pressable implementations and aligns relation prop types with supported array inputs without introducing an actionable merge-blocking risk; it is merge-ready after normal checks and review.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change to Pressable props, including hover testing support and broadened gesture relation types.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves React Native Testing Library (RNTL) compatibility for Pressable by forwarding hover handlers via testOnly_* props (guarded to test env only), and aligns the Pressable relation prop TypeScript types with the documented/runtime-supported behavior of accepting either a gesture or an array of gestures.

Changes:

  • Forward onHoverIn/onHoverOut as testOnly_onHoverIn/testOnly_onHoverOut from all Pressable engines (LegacyPressable, StatefulPressable, PressableWithTouchable) under isTestEnv().
  • Add testOnly_onHoverIn/testOnly_onHoverOut to button prop types (ButtonProps, LegacyRawButtonProps).
  • Widen Pressable relation prop types (simultaneousWith/requireToFail/block) from AnyGesture to AnyGesture | AnyGesture[], matching JSDoc and runtime handling.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx Forwards hover handlers as testOnly_* props in test env for the relation-enabled engine.
packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx Forwards hover handlers as testOnly_* props in test env for the default v3 engine.
packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx Widens relation prop types to accept a gesture or an array of gestures.
packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx Forwards hover handlers as testOnly_* props in test env for the legacy Pressable.
packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx Extends ButtonProps with testOnly_onHoverIn/testOnly_onHoverOut declarations.
packages/react-native-gesture-handler/src/components/GestureButtonsProps.ts Extends legacy button prop types with testOnly_onHoverIn/testOnly_onHoverOut.
packages/react-native-gesture-handler/src/tests/mocks.test.tsx Adds regression tests asserting hover testOnly_* props are exposed for both v3 engines.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@m-bert
m-bert requested a review from j-piasecki August 14, 2026 08:49
@m-bert
m-bert merged commit 3e4497e into main Aug 14, 2026
7 checks passed
@m-bert
m-bert deleted the @mbert/pressable-testonly-hover branch August 14, 2026 09:12
m-bert added a commit that referenced this pull request Aug 14, 2026
## Description

Follow-up to #4416. None of the `Pressable` engines forwarded hover
handlers as `testOnly_*` props, so `fireEvent(element, 'hoverIn')` from
React Native Testing Library had no way to reach
`onHoverIn`/`onHoverOut`. RNTL resolves `testOnly_on{EventName}`
generically for any event, so exposing the props is all that's needed.

This adds `testOnly_onHoverIn`/`testOnly_onHoverOut` to the button props
and forwards them, guarded by `isTestEnv()`, from all three engines:
legacy `Pressable`, `StatefulPressable` and `PressableWithTouchable`.

Also widens the relation props
(`simultaneousWith`/`requireToFail`/`block`) from `AnyGesture` to
`AnyGesture | AnyGesture[]`. The JSDoc already promises a gesture object
or an array of gesture objects and the runtime handles arrays in both
directions (`relationUtils` flattens them into handler tags and pushes
the symmetric relation onto each array element), only the prop type was
narrowed.

## Test plan

Added tests in `src/__tests__/mocks.test.tsx` asserting the hover props
are wired on the button for both v3 engines — relation-free and routed
to `StatefulPressable` via `simultaneousWith={[]}` (which the type
widening makes legal). Both fail without the engine changes.

In `packages/react-native-gesture-handler`: `yarn test`, `yarn ts-check`
and `yarn lint:js` pass.
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.

3 participants