Skip to content

Commit 3822b3e

Browse files
authored
[0.81] Implement onClick and onAuxClick (#15920)
* Implement onClick (#15889) * Implement onClick * Change files * Add onAuxClick event * Update snapshots and fix lint error * Fix NativeModule templates to work with clang (#15917) * Fix NativeModule templates to work with clang * Change files * update change files * lint * lint * Remove homeUIA tests * fix
1 parent 6c4fb9b commit 3822b3e

File tree

19 files changed

+601
-7028
lines changed

19 files changed

+601
-7028
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix NativeModule templates to work with clang",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Implement onClick",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT License.
4+
*
5+
* @flow strict-local
6+
* @format
7+
*/
8+
9+
'use strict';
10+
11+
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
12+
13+
const React = require('react');
14+
import {Pressable, StyleSheet, View} from 'react-native';
15+
import RNTesterText from '../../components/RNTesterText';
16+
17+
function PointerClickEventsExample(): React.Node {
18+
const [text, setText] = React.useState(
19+
'onClick should cause the box to go red, onAuxClick will cause it go green',
20+
);
21+
const [bgColor, setBgColor] = React.useState('gray');
22+
return (
23+
<View>
24+
<View
25+
accessible
26+
testID="pointer-click-target"
27+
style={[styles.targetBox, {backgroundColor: bgColor}]}
28+
onClick={e => {
29+
setBgColor('red');
30+
setText(
31+
'onClick.nativeEvent: ' + JSON.stringify(e.nativeEvent, null, 2),
32+
);
33+
}}
34+
onAuxClick={e => {
35+
setBgColor('green');
36+
setText(
37+
'onAuxClick.nativeEvent: ' + JSON.stringify(e.nativeEvent, null, 2),
38+
);
39+
}}
40+
/>
41+
<RNTesterText accessible testID="pointer-click-text">
42+
{text}
43+
</RNTesterText>
44+
</View>
45+
);
46+
}
47+
48+
exports.displayName = 'PointerClickExample';
49+
exports.framework = 'React';
50+
exports.category = 'Basic';
51+
exports.title = 'Pointer Clicks';
52+
exports.documentationURL =
53+
'https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event';
54+
exports.description = 'Tests that onClick and onAuxClick work.';
55+
56+
exports.examples = [
57+
{
58+
title: 'onClick/onAuxClick test',
59+
description:
60+
'Click the box with different pointers/buttons to test pointer click events.',
61+
render: function (): React.Node {
62+
return <PointerClickEventsExample />;
63+
},
64+
},
65+
] as Array<RNTesterModuleExample>;
66+
67+
const styles = StyleSheet.create({
68+
targetBox: {
69+
width: 200,
70+
height: 200,
71+
margin: 10,
72+
borderRadius: 10,
73+
justifyContent: 'center',
74+
alignItems: 'center',
75+
},
76+
});

packages/@react-native-windows/tester/src/js/utils/RNTesterList.windows.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ const APIs: Array<RNTesterModuleInfo> = ([
401401
category: 'Basic',
402402
module: require('../examples/PointerEvents/PointerEventsExample'),
403403
},
404+
{
405+
key: 'PointerClickEventsExample',
406+
category: 'Basic',
407+
module: require('../examples-win/Pointer/PointerClickEventsExample'),
408+
},
404409
{
405410
key: 'PointerButtonExample',
406411
category: 'Basic',

packages/e2e-test-app-fabric/test/HomeUIADump.test.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT License.
4+
*
5+
* @format
6+
*/
7+
8+
import {goToApiExample} from './RNTesterNavigation';
9+
import {verifyNoErrorLogs} from './Helpers';
10+
import {app} from '@react-native-windows/automation';
11+
12+
beforeAll(async () => {
13+
// If window is partially offscreen, tests will fail to click on certain elements
14+
await app.setWindowPosition(0, 0);
15+
await app.setWindowSize(1000, 1250);
16+
await goToApiExample('Pointer Clicks');
17+
});
18+
19+
afterEach(async () => {
20+
await verifyNoErrorLogs();
21+
});
22+
23+
describe('Pointer onClick Test', () => {
24+
test('onClick reports correct native event properties on left click', async () => {
25+
const component = await app.findElementByTestID('pointer-click-target');
26+
await component.waitForDisplayed({timeout: 5000});
27+
28+
// Left click triggers onPointerDown with button=0
29+
await component.click();
30+
const stateText = await app.findElementByTestID('pointer-click-text');
31+
32+
await app.waitUntil(
33+
async () => {
34+
const currentText = await stateText.getText();
35+
return (
36+
currentText.includes('"button": 0') && currentText.includes('onClick')
37+
);
38+
},
39+
{
40+
timeout: 5000,
41+
timeoutMsg:
42+
'State text not updated after onClick with button property.',
43+
},
44+
);
45+
46+
const text = await stateText.getText();
47+
expect(text).toMatchSnapshot();
48+
});
49+
test('onAuxClick reports correct native event properties on middle click', async () => {
50+
const component = await app.findElementByTestID('pointer-click-target');
51+
await component.waitForDisplayed({timeout: 5000});
52+
53+
// Middle click triggers onPointerDown with button=1
54+
await component.click({button: 'middle'});
55+
const stateText = await app.findElementByTestID('pointer-click-text');
56+
57+
await app.waitUntil(
58+
async () => {
59+
const currentText = await stateText.getText();
60+
return (
61+
currentText.includes('"button": 1') &&
62+
currentText.includes('onAuxClick')
63+
);
64+
},
65+
{
66+
timeout: 5000,
67+
timeoutMsg:
68+
'State text not updated after onAuxClick with middle button property.',
69+
},
70+
);
71+
72+
const text = await stateText.getText();
73+
expect(text).toMatchSnapshot();
74+
});
75+
test('onAuxClick reports correct native event properties on right click', async () => {
76+
const component = await app.findElementByTestID('pointer-click-target');
77+
await component.waitForDisplayed({timeout: 5000});
78+
79+
// Middle click triggers onPointerDown with button=2
80+
await component.click({button: 'right'});
81+
const stateText = await app.findElementByTestID('pointer-click-text');
82+
83+
await app.waitUntil(
84+
async () => {
85+
const currentText = await stateText.getText();
86+
return (
87+
currentText.includes('"button": 2') &&
88+
currentText.includes('onAuxClick')
89+
);
90+
},
91+
{
92+
timeout: 5000,
93+
timeoutMsg:
94+
'State text not updated after onAuxClick with right button property.',
95+
},
96+
);
97+
98+
const text = await stateText.getText();
99+
expect(text).toMatchSnapshot();
100+
});
101+
});

0 commit comments

Comments
 (0)