-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add button property mouse events #15819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Harini Malothu (HariniMalothu17)
merged 20 commits into
microsoft:main
from
HariniMalothu17:fix/add-button-property-mouse-events
Mar 24, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
df7c45b
Workflow for stale branches
6de27e6
Workflow for stale branches
4b874db
Merge pull request #13 from HariniMalothu17/cleanupstalebranch-v2
HariniMalothu17 a68bba6
Merge branch 'microsoft:main' into main
HariniMalothu17 6148e40
Merge branch 'main' of https://github.com/HariniMalothu17/react-nativ…
4f309af
Implement button property
a7e43ab
Merge branch 'main' into fix/add-button-property-mouse-events
HariniMalothu17 21b8722
Change files
dee3f22
Merge branch 'fix/add-button-property-mouse-events' of https://github…
49dc4ac
Forked BaseViewProps,Added examples
f51e3bb
Updated example changes
267060a
fix lint
715b152
Merge branch 'main' into fix/add-button-property-mouse-events
HariniMalothu17 88f3ae2
added e2e test cases
f2803de
Merge branch 'main' into fix/add-button-property-mouse-events
HariniMalothu17 9fba849
update snapshots
1600e7d
Merge branch 'fix/add-button-property-mouse-events' of https://github…
17f17e3
update snapshot
aeb3afd
updated test cases
0a3b7cf
Merge branch 'main' into fix/add-button-property-mouse-events
HariniMalothu17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/react-native-windows-c4c264df-7619-4559-b43f-9761d5d68d63.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "Implement button property", | ||
| "packageName": "react-native-windows", | ||
| "email": "hmalothu@microsoft.com", | ||
| "dependentChangeType": "none" | ||
| } |
115 changes: 115 additions & 0 deletions
115
.../@react-native-windows/tester/src/js/examples-win/Pointer/PointerButtonExample.windows.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| * | ||
| * @flow strict-local | ||
| * @format | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
|
||
| const React = require('react'); | ||
| const {StyleSheet, Text, View} = require('react-native'); | ||
|
|
||
| function buttonLabel(button: number): string { | ||
| switch (button) { | ||
| case 0: | ||
| return 'Left'; | ||
| case 1: | ||
| return 'Middle'; | ||
| case 2: | ||
| return 'Right'; | ||
| case 3: | ||
| return 'X1'; | ||
| case 4: | ||
| return 'X2'; | ||
| default: | ||
| return `Unknown(${button})`; | ||
| } | ||
| } | ||
|
|
||
| function PointerDownButtonExample(): React.Node { | ||
| const [text, setText] = React.useState( | ||
| 'Click the box to test pointer events', | ||
| ); | ||
| return ( | ||
| <View> | ||
| <Text accessible={true} testID="pointer-button-state">{text}</Text> | ||
| <View | ||
| accessible={true} | ||
| testID="pointer-button-target" | ||
| style={styles.targetBox} | ||
| onPointerDown={(e: any) => { | ||
| const {button, buttons} = e.nativeEvent; | ||
| setText( | ||
| `PointerDown: ${buttonLabel(button)} (button=${button}, buttons=${buttons})`, | ||
| ); | ||
| }} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function PointerUpButtonExample(): React.Node { | ||
| const [text, setText] = React.useState( | ||
| 'Click the box to test pointer up events', | ||
| ); | ||
| return ( | ||
| <View> | ||
| <Text accessible={true} testID="pointer-up-button-state">{text}</Text> | ||
| <View | ||
| accessible={true} | ||
| testID="pointer-up-button-target" | ||
| style={styles.targetBox} | ||
| onPointerUp={(e: any) => { | ||
| const {button, buttons} = e.nativeEvent; | ||
| setText( | ||
| `PointerUp: ${buttonLabel(button)} (button=${button}, buttons=${buttons})`, | ||
| ); | ||
| }} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| exports.displayName = 'PointerButtonExample'; | ||
| exports.framework = 'React'; | ||
| exports.category = 'Basic'; | ||
| exports.title = 'Pointer Button'; | ||
| exports.documentationURL = | ||
| 'https://developer.mozilla.org/docs/Web/API/PointerEvent/button'; | ||
| exports.description = | ||
| 'Tests that PointerEvent.button and PointerEvent.buttons are correctly populated.'; | ||
|
|
||
| exports.examples = [ | ||
| { | ||
| title: 'onPointerDown button property', | ||
| description: | ||
| 'Click the box to verify the button property on onPointerDown events.', | ||
| render: function (): React.Node { | ||
| return <PointerDownButtonExample />; | ||
| }, | ||
| }, | ||
| { | ||
| title: 'onPointerUp button property', | ||
| description: | ||
| 'Click the box to verify the button property on onPointerUp events.', | ||
| render: function (): React.Node { | ||
| return <PointerUpButtonExample />; | ||
| }, | ||
| }, | ||
| ] as Array<RNTesterModuleExample>; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| targetBox: { | ||
| backgroundColor: 'magenta', | ||
| width: 200, | ||
| height: 200, | ||
| margin: 10, | ||
| borderRadius: 10, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 216 additions & 0 deletions
216
packages/e2e-test-app-fabric/test/PointerButtonComponentTest.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| * | ||
| * @format | ||
| */ | ||
|
|
||
| import {dumpVisualTree} from '@react-native-windows/automation-commands'; | ||
| import {goToApiExample} from './RNTesterNavigation'; | ||
| import {verifyNoErrorLogs} from './Helpers'; | ||
| import {app} from '@react-native-windows/automation'; | ||
|
|
||
| beforeAll(async () => { | ||
| // If window is partially offscreen, tests will fail to click on certain elements | ||
| await app.setWindowPosition(0, 0); | ||
| await app.setWindowSize(1000, 1250); | ||
| await goToApiExample('Pointer Button'); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await verifyNoErrorLogs(); | ||
| }); | ||
|
|
||
| const searchBox = async (input: string) => { | ||
| const searchBox = await app.findElementByTestID('example_search'); | ||
| await app.waitUntil( | ||
| async () => { | ||
| await searchBox.setValue(input); | ||
| if (input === '') { | ||
| return (await searchBox.getText()) === 'Search...'; | ||
| } else { | ||
| return (await searchBox.getText()) === input; | ||
| } | ||
| }, | ||
| { | ||
| interval: 1500, | ||
| timeout: 5000, | ||
| timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| describe('Pointer Button Tests', () => { | ||
| test('onPointerDown reports correct button property on left click', async () => { | ||
| await searchBox('onPointerDown'); | ||
| const component = await app.findElementByTestID('pointer-button-target'); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
| const dump = await dumpVisualTree('pointer-button-target'); | ||
| expect(dump).toMatchSnapshot(); | ||
|
|
||
| // Left click triggers onPointerDown with button=0 | ||
| await component.click(); | ||
| const stateText = await app.findElementByTestID('pointer-button-state'); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const currentText = await stateText.getText(); | ||
| return currentText.includes('button=0'); | ||
| }, | ||
| { | ||
| timeout: 5000, | ||
| timeoutMsg: | ||
| 'State text not updated after onPointerDown with button property.', | ||
| }, | ||
| ); | ||
|
|
||
| const text = await stateText.getText(); | ||
| expect(text).toContain('PointerDown'); | ||
| expect(text).toContain('button=0'); | ||
| expect(text).toContain('buttons=1'); | ||
| }); | ||
| test('onPointerDown reports correct button property on middle click', async () => { | ||
| await searchBox('onPointerDown'); | ||
| const component = await app.findElementByTestID('pointer-button-target'); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
|
|
||
| // Middle click triggers onPointerDown with button=1 | ||
| await component.click({button: 'middle'}); | ||
| const stateText = await app.findElementByTestID('pointer-button-state'); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const currentText = await stateText.getText(); | ||
| return currentText.includes('button=1'); | ||
| }, | ||
| { | ||
| timeout: 5000, | ||
| timeoutMsg: | ||
| 'State text not updated after onPointerDown with middle button property.', | ||
| }, | ||
| ); | ||
|
|
||
| const text = await stateText.getText(); | ||
| expect(text).toContain('PointerDown'); | ||
| expect(text).toContain('button=1'); | ||
| expect(text).toContain('buttons=4'); | ||
| }); | ||
| test('onPointerDown reports correct button property on right click', async () => { | ||
| await searchBox('onPointerDown'); | ||
| const component = await app.findElementByTestID('pointer-button-target'); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
|
|
||
| // Right click triggers onPointerDown with button=2 | ||
| await component.click({button: 'right'}); | ||
| const stateText = await app.findElementByTestID('pointer-button-state'); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const currentText = await stateText.getText(); | ||
| return currentText.includes('button=2'); | ||
| }, | ||
| { | ||
| timeout: 5000, | ||
| timeoutMsg: | ||
| 'State text not updated after onPointerDown with right button property.', | ||
| }, | ||
| ); | ||
|
|
||
| const text = await stateText.getText(); | ||
| expect(text).toContain('PointerDown'); | ||
| expect(text).toContain('button=2'); | ||
| expect(text).toContain('buttons=2'); | ||
| }); | ||
| test('onPointerUp reports correct button property on left click', async () => { | ||
| await searchBox('onPointerUp'); | ||
| const component = await app.findElementByTestID( | ||
| 'pointer-up-button-target', | ||
| ); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
| const dump = await dumpVisualTree('pointer-up-button-target'); | ||
| expect(dump).toMatchSnapshot(); | ||
|
|
||
| // Left click release triggers onPointerUp with button=0 | ||
| await component.click(); | ||
| const stateText = await app.findElementByTestID( | ||
| 'pointer-up-button-state', | ||
| ); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const currentText = await stateText.getText(); | ||
| return currentText.includes('button=0'); | ||
| }, | ||
| { | ||
| timeout: 5000, | ||
| timeoutMsg: | ||
| 'State text not updated after onPointerUp with button property.', | ||
| }, | ||
| ); | ||
|
|
||
| const text = await stateText.getText(); | ||
| expect(text).toContain('PointerUp'); | ||
| expect(text).toContain('button=0'); | ||
| expect(text).toContain('buttons=0'); | ||
| }); | ||
| test('onPointerUp reports correct button property on middle click', async () => { | ||
| await searchBox('onPointerUp'); | ||
| const component = await app.findElementByTestID( | ||
| 'pointer-up-button-target', | ||
| ); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
|
|
||
| // Middle click release triggers onPointerUp with button=1 | ||
| await component.click({button: 'middle'}); | ||
| const stateText = await app.findElementByTestID( | ||
| 'pointer-up-button-state', | ||
| ); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const currentText = await stateText.getText(); | ||
| return currentText.includes('button=1'); | ||
| }, | ||
| { | ||
| timeout: 5000, | ||
| timeoutMsg: | ||
| 'State text not updated after onPointerUp with middle button property.', | ||
| }, | ||
| ); | ||
|
|
||
| const text = await stateText.getText(); | ||
| expect(text).toContain('PointerUp'); | ||
| expect(text).toContain('button=1'); | ||
| expect(text).toContain('buttons=0'); | ||
| }); | ||
| test('onPointerUp reports correct button property on right click', async () => { | ||
| await searchBox('onPointerUp'); | ||
| const component = await app.findElementByTestID( | ||
| 'pointer-up-button-target', | ||
| ); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
|
|
||
| // Right click release triggers onPointerUp with button=2 | ||
| await component.click({button: 'right'}); | ||
| const stateText = await app.findElementByTestID( | ||
| 'pointer-up-button-state', | ||
| ); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const currentText = await stateText.getText(); | ||
| return currentText.includes('button=2'); | ||
| }, | ||
| { | ||
| timeout: 5000, | ||
| timeoutMsg: | ||
| 'State text not updated after onPointerUp with right button property.', | ||
| }, | ||
| ); | ||
|
|
||
| const text = await stateText.getText(); | ||
| expect(text).toContain('PointerUp'); | ||
| expect(text).toContain('button=2'); | ||
| expect(text).toContain('buttons=0'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is also a way to trigger clicks with other buttons, so you can verify that those work too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the test cases