Skip to content

Commit 805e87f

Browse files
committed
Only pass in modified onKeyDown and onKeyUp if specified.
1 parent 39c1dfe commit 805e87f

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

packages/react-native/Libraries/Components/Pressable/__tests__/__snapshots__/Pressable-test.js.snap

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ exports[`<Pressable /> should render as expected: should deep render when mocked
2424
collapsable={false}
2525
enableFocusRing={true}
2626
focusable={true}
27+
keyDownEvents={
28+
Array [
29+
Object {
30+
"key": " ",
31+
},
32+
Object {
33+
"key": "Enter",
34+
},
35+
]
36+
}
2737
mouseDownCanMoveWindow={false}
2838
onBlur={[Function]}
2939
onClick={[Function]}
@@ -63,6 +73,16 @@ exports[`<Pressable /> should render as expected: should deep render when not mo
6373
collapsable={false}
6474
enableFocusRing={true}
6575
focusable={true}
76+
keyDownEvents={
77+
Array [
78+
Object {
79+
"key": " ",
80+
},
81+
Object {
82+
"key": "Enter",
83+
},
84+
]
85+
}
6686
mouseDownCanMoveWindow={false}
6787
onBlur={[Function]}
6888
onClick={[Function]}
@@ -102,6 +122,16 @@ exports[`<Pressable disabled={true} /> should be disabled when disabled is true:
102122
collapsable={false}
103123
enableFocusRing={false}
104124
focusable={false}
125+
keyDownEvents={
126+
Array [
127+
Object {
128+
"key": " ",
129+
},
130+
Object {
131+
"key": "Enter",
132+
},
133+
]
134+
}
105135
mouseDownCanMoveWindow={false}
106136
onBlur={[Function]}
107137
onClick={[Function]}
@@ -141,6 +171,16 @@ exports[`<Pressable disabled={true} /> should be disabled when disabled is true:
141171
collapsable={false}
142172
enableFocusRing={false}
143173
focusable={false}
174+
keyDownEvents={
175+
Array [
176+
Object {
177+
"key": " ",
178+
},
179+
Object {
180+
"key": "Enter",
181+
},
182+
]
183+
}
144184
mouseDownCanMoveWindow={false}
145185
onBlur={[Function]}
146186
onClick={[Function]}
@@ -180,6 +220,16 @@ exports[`<Pressable disabled={true} accessibilityState={{}} /> should be disable
180220
collapsable={false}
181221
enableFocusRing={false}
182222
focusable={false}
223+
keyDownEvents={
224+
Array [
225+
Object {
226+
"key": " ",
227+
},
228+
Object {
229+
"key": "Enter",
230+
},
231+
]
232+
}
183233
mouseDownCanMoveWindow={false}
184234
onBlur={[Function]}
185235
onClick={[Function]}
@@ -219,6 +269,16 @@ exports[`<Pressable disabled={true} accessibilityState={{}} /> should be disable
219269
collapsable={false}
220270
enableFocusRing={false}
221271
focusable={false}
272+
keyDownEvents={
273+
Array [
274+
Object {
275+
"key": " ",
276+
},
277+
Object {
278+
"key": "Enter",
279+
},
280+
]
281+
}
222282
mouseDownCanMoveWindow={false}
223283
onBlur={[Function]}
224284
onClick={[Function]}
@@ -258,6 +318,16 @@ exports[`<Pressable disabled={true} accessibilityState={{checked: true}} /> shou
258318
collapsable={false}
259319
enableFocusRing={false}
260320
focusable={false}
321+
keyDownEvents={
322+
Array [
323+
Object {
324+
"key": " ",
325+
},
326+
Object {
327+
"key": "Enter",
328+
},
329+
]
330+
}
261331
mouseDownCanMoveWindow={false}
262332
onBlur={[Function]}
263333
onClick={[Function]}
@@ -297,6 +367,16 @@ exports[`<Pressable disabled={true} accessibilityState={{checked: true}} /> shou
297367
collapsable={false}
298368
enableFocusRing={false}
299369
focusable={false}
370+
keyDownEvents={
371+
Array [
372+
Object {
373+
"key": " ",
374+
},
375+
Object {
376+
"key": "Enter",
377+
},
378+
]
379+
}
300380
mouseDownCanMoveWindow={false}
301381
onBlur={[Function]}
302382
onClick={[Function]}
@@ -336,6 +416,16 @@ exports[`<Pressable disabled={true} accessibilityState={{disabled: false}} /> sh
336416
collapsable={false}
337417
enableFocusRing={false}
338418
focusable={false}
419+
keyDownEvents={
420+
Array [
421+
Object {
422+
"key": " ",
423+
},
424+
Object {
425+
"key": "Enter",
426+
},
427+
]
428+
}
339429
mouseDownCanMoveWindow={false}
340430
onBlur={[Function]}
341431
onClick={[Function]}
@@ -375,6 +465,16 @@ exports[`<Pressable disabled={true} accessibilityState={{disabled: false}} /> sh
375465
collapsable={false}
376466
enableFocusRing={false}
377467
focusable={false}
468+
keyDownEvents={
469+
Array [
470+
Object {
471+
"key": " ",
472+
},
473+
Object {
474+
"key": "Enter",
475+
},
476+
]
477+
}
378478
mouseDownCanMoveWindow={false}
379479
onBlur={[Function]}
380480
onClick={[Function]}

packages/react-native/Libraries/Components/TextInput/TextInput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,8 +1863,8 @@ function InternalTextInput(props: TextInputProps): React.Node {
18631863
onChange={_onChange}
18641864
onContentSizeChange={props.onContentSizeChange}
18651865
onFocus={_onFocus}
1866-
onKeyDown={_onKeyDown} // [macOS]
1867-
onKeyUp={_onKeyUp} // [macOS]
1866+
{...(otherProps.onKeyDown && {onKeyDown: _onKeyDown})} // [macOS]
1867+
{...(otherProps.onKeyUp && {onKeyUp: _onKeyUp})} // [macOS]
18681868
onScroll={_onScroll}
18691869
onSelectionChange={_onSelectionChange}
18701870
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}

packages/react-native/Libraries/Components/View/View.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ const View: component(
151151
: importantForAccessibility
152152
}
153153
nativeID={id ?? nativeID}
154-
onKeyDown={_onKeyDown} // [macOS]
155-
onKeyUp={_onKeyUp} // [macOS]
154+
{...(otherProps.onKeyDown && {onKeyDown: _onKeyDown})} // [macOS]
155+
{...(otherProps.onKeyUp && {onKeyUp: _onKeyUp})} // [macOS]
156156
ref={forwardedRef}
157157
/>
158158
);

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,10 @@ export type TextInputProps = $ReadOnly<{
34293429
submitBehavior?: ?SubmitBehavior,
34303430
style?: ?TextStyleProp,
34313431
value?: ?Stringish,
3432+
keyDownEvents?: ?$ReadOnlyArray<HandledKeyEvent>,
3433+
keyUpEvents?: ?$ReadOnlyArray<HandledKeyEvent>,
3434+
onKeyDown?: ?(e: KeyEvent) => mixed,
3435+
onKeyUp?: ?(e: KeyEvent) => mixed,
34323436
}>;
34333437
export type TextInputComponentStatics = $ReadOnly<{
34343438
State: $ReadOnly<{

0 commit comments

Comments
 (0)