Skip to content
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

Return and Space keys do not trigger onPress events #1623

Merged
merged 62 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
685f103
Update scripts to publish react-native-macos-init
tom-un Apr 4, 2020
8ccd26c
Merge remote-tracking branch 'ms/master'
tom-un Apr 4, 2020
45d2ee2
Merge remote-tracking branch 'ms/master'
tom-un Apr 4, 2020
1e2c329
Clean up merge markers
tom-un Apr 4, 2020
408dae3
Merge remote-tracking branch 'ms/master'
tom-un Apr 6, 2020
bdaa8ad
Merge remote-tracking branch 'ms/master'
tom-un Apr 7, 2020
5a67ae0
Restored ios:macos RNTester parity except for InputAccessoryView.
tom-un Apr 13, 2020
e5a6df2
Revert "Restored ios:macos RNTester parity except for InputAccessoryV…
tom-un Apr 13, 2020
4bca23c
Merge remote-tracking branch 'ms/master'
tom-un Apr 16, 2020
d067629
Merge remote-tracking branch 'ms/master'
tom-un Apr 21, 2020
6ed01c8
Merge remote-tracking branch 'ms/master'
tom-un Apr 28, 2020
ae5cc57
Merge remote-tracking branch 'ms/master'
tom-un Apr 29, 2020
caf0975
Merge remote-tracking branch 'ms/master'
tom-un May 1, 2020
e3fbee9
Merge remote-tracking branch 'ms/master'
tom-un May 1, 2020
a75050c
Merge remote-tracking branch 'ms/master'
tom-un May 2, 2020
3a77e37
Merge remote-tracking branch 'ms/master'
tom-un May 2, 2020
d10ff74
Merge remote-tracking branch 'ms/master'
tom-un May 3, 2020
dd11d73
Merge remote-tracking branch 'ms/master'
tom-un May 4, 2020
ba2730b
Merge remote-tracking branch 'ms/master'
tom-un May 4, 2020
5da14a9
Remove unnecessary android builds and tar file upload.
tom-un May 5, 2020
b1a873b
Merge remote-tracking branch 'ms/master'
rnbot May 5, 2020
bca9ae9
Merge remote-tracking branch 'ms/master'
rnbot May 5, 2020
7ff5624
Merge remote-tracking branch 'ms/master'
rnbot May 5, 2020
1056600
Merge remote-tracking branch 'ms/master'
rnbot May 6, 2020
d3422e3
Merge remote-tracking branch 'ms/master'
rnbot May 6, 2020
92c66ac
Merge remote-tracking branch 'ms/master'
rnbot May 7, 2020
b295454
Merge remote-tracking branch 'ms/master'
rnbot May 8, 2020
1bdf8c7
Merge remote-tracking branch 'ms/master'
rnbot May 8, 2020
b880837
Merge remote-tracking branch 'ms/master'
rnbot May 8, 2020
3c7c7c3
Merge remote-tracking branch 'ms/master'
rnbot May 8, 2020
93c5ecb
Merge remote-tracking branch 'ms/master'
rnbot May 11, 2020
04ba713
Merge remote-tracking branch 'ms/master'
rnbot May 12, 2020
b3be546
Merge remote-tracking branch 'ms/master'
tom-un May 18, 2020
046bde3
Merge remote-tracking branch 'ms/master'
tom-un May 18, 2020
302493e
Merge remote-tracking branch 'ms/master'
tom-un May 20, 2020
4ebb937
Merge remote-tracking branch 'ms/master'
tom-un May 20, 2020
5bdb247
Merge remote-tracking branch 'ms/master'
tom-un May 22, 2020
07bea18
Merge remote-tracking branch 'ms/master'
tom-un May 26, 2020
51f76ed
Merge remote-tracking branch 'ms/master'
tom-un Jun 1, 2020
6f814b4
Merge remote-tracking branch 'ms/master'
tom-un Jun 11, 2020
e69efe4
Merge remote-tracking branch 'ms/master'
tom-un Jun 17, 2020
76449c6
Merge remote-tracking branch 'ms/master'
tom-un Jun 23, 2020
6746b18
Merge remote-tracking branch 'ms/master'
tom-un Jul 1, 2020
e822b86
Merge remote-tracking branch 'ms/master'
tom-un Jul 13, 2020
e6f9e2d
Merge remote-tracking branch 'ms/master'
tom-un Jul 14, 2020
0676b93
Merge remote-tracking branch 'ms/master'
tom-un Jul 17, 2020
ab4a6d9
Merge remote-tracking branch 'ms/master'
tom-un Jul 22, 2020
ca7617f
Merge remote-tracking branch 'ms/master' into master
tom-un Aug 20, 2020
f226a7d
Merge remote-tracking branch 'ms/master' into master
tom-un Sep 1, 2020
582cfba
Merge remote-tracking branch 'ms/master' into master
tom-un Sep 4, 2020
edfd0ee
Merge remote-tracking branch 'ms/master' into master
tom-un Sep 22, 2020
b3572bb
Merge remote-tracking branch 'ms/master' into master
tom-un Oct 2, 2020
c3c3957
Merge remote-tracking branch 'ms/master' into master
tom-un Oct 8, 2020
9189e5e
Merge remote-tracking branch 'upstream/master'
tom-un Nov 17, 2020
5a7b082
Merge branch 'microsoft:main' into master
tom-un Nov 27, 2022
dd95e94
Merge branch 'microsoft:main' into master
tom-un Jan 6, 2023
2497bb7
Fix pressability enter/return and spacebar key events
tom-un Jan 6, 2023
5ad9a1b
Don't change validKeysDown/Up for components that explicitly set them
tom-un Jan 6, 2023
f05167a
Added event.defaultPrevented check to key events
tom-un Jan 9, 2023
550da45
Fixed spacing in RCTView.m
tom-un Jan 9, 2023
b3cc601
Ignore key event props not matching press events
tom-un Jan 10, 2023
4f1e62a
Update Pressability.js
Saadnajmi Jan 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Libraries/Pressability/Pressability.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,35 @@ export default class Pressability {
if (onKeyDown != null) {
onKeyDown(event);
}
// Pressables on macOS should respond to the enter/return and spacebar keys.
// The keyDown event triggers a press event as well as the pressIn effect mimicking a native control behavior.
if (
(event.nativeEvent.key === 'Enter' ||
event.nativeEvent.key === ' ') &&
event.defaultPrevented !== true
) {
const {onPress, onPressIn} = this._config;
// $FlowFixMe: PressEvents don't mesh with keyboarding APIs. Keep legacy behavior of passing KeyEvents instead
onPress && onPress(event);
// $FlowFixMe: PressEvents don't mesh with keyboarding APIs. Keep legacy behavior of passing KeyEvents instead
onPressIn && onPressIn(event);
Saadnajmi marked this conversation as resolved.
Show resolved Hide resolved
}
},
onKeyUp: (event: KeyEvent): void => {
const {onKeyUp} = this._config;
if (onKeyUp != null) {
onKeyUp(event);
}
// The keyUp event triggers the pressOut effect.
if (
(event.nativeEvent.key === 'Enter' ||
event.nativeEvent.key === ' ') &&
event.defaultPrevented !== true
) {
const {onPressOut} = this._config;
// $FlowFixMe: PressEvents don't mesh with keyboarding APIs. Keep legacy behavior of passing KeyEvents instead
onPressOut && onPressOut(event);
}
},
};
// ]TODO(macOS GH#774)
Expand Down
6 changes: 6 additions & 0 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,12 @@ - (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
NSArray<NSString *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];

// If the view is focusable and the component didn't explicity set the validKeysDown or Up,
// allow enter/return and spacebar key events to mimic the behavior of native controls.
if (self.focusable && validKeys == nil) {
validKeys = @[@"Enter", @" "];
Saadnajmi marked this conversation as resolved.
Show resolved Hide resolved
}

// Only post events for keys we care about
if (![validKeys containsObject:key]) {
return nil;
Expand Down