-
Notifications
You must be signed in to change notification settings - Fork 163
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
FocusZone (macOS): New prop to ignore OS keyboard shortcut preference #2267
Merged
Conversation
This file contains 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
4 tasks
Saadnajmi
commented
Oct 27, 2022
lyzhan7
reviewed
Oct 27, 2022
lyzhan7
reviewed
Oct 27, 2022
chiuam
reviewed
Oct 27, 2022
chiuam
reviewed
Oct 27, 2022
amgleitman
approved these changes
Oct 27, 2022
Saadnajmi
added a commit
to Saadnajmi/fluentui-react-native
that referenced
this pull request
Nov 9, 2022
…eference (microsoft#2267)" This reverts commit d5c85ec.
This was referenced Nov 9, 2022
ghost
pushed a commit
that referenced
this pull request
Nov 18, 2022
… views (#2329) ### Platforms Impacted - [ ] iOS - [x] macOS - [ ] win32 (Office) - [ ] windows - [ ] android ### Description of changes This is a simpler version of #2267 . Instead of adding a new prop to differentiate whether we focus on key views vs first responders, this one will just... focus on first responders unconditionally. The reasoning is as follows: 1) FocusZone itself doesn't override `canBecomeKeyView. So FocusZone itself respects the system keyboard navigation preference. 2) FocusZone itself is pretending to be "one big focusable view" to the eyes of Appkit. Its job is to move focus inside itself between focusable views. Once it gains focus (via the key view loop or programmatically), it probably doesn't matter whether its children were key views. If you're using a FocusZone for your custom control, you probably still want the keyboard events to work regardless. How this affects components: - For the case of ContextualMenu, we call `focusZoneRef.current.focus()` once the menu is opened. This will force focus on the Menu regardless of the OS preference (which we want), and then with this change keyboard navigation will work. - For the case of Radiogroup: Native Appkit RadioGroups are not key views if the keyboard navigation preference is disabled, and you can't move focus or arrow key through them at all. With our JS Radiogroup (and Native RadioGroup), this behavior should be the same, since the enclosing FocusZone will not become a key view. ### Verification Locally side loaded the built `libRCTFocusZone.a` to test a partner scenario, and it worked fine with no regressions. Tested ContextualMenu and RadioGroup and didn't find any regressions. ### Pull request checklist This PR has considered (when applicable): - [ ] Automated Tests - [ ] Documentation and examples - [ ] Keyboard Accessibility - [ ] Voiceover - [ ] Internationalization and Right-to-left Layouts
nakambo
added a commit
that referenced
this pull request
Jan 29, 2025
When a TextInput is not inside a FocusZone, it properly participates in the key view loop in that Tab\Shift+Tab will place focus on the inner `RCTUITextView`, instead of the outer `RCTBaseTextInputView` subclass. This is due to [overriding](https://github.com/microsoft/react-native-macos/blob/b7033b3513d98b20a08ec20abfe2b9bb712c68d4/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm#L1147C1-L1150C2) the `canBecomeKeyView` in that base class. However, the FocusZone control does not look at that property -- instead it only considers `canBecomeFirstResponder`, as seen in #2329. Although it seems like the logical next step to use `canBecomeKeyView` in the FocusZone, that was previously done with #2267 but later reverted in #2322 since it broke things downstream. Instead, we'll make a compromise and leak some of the text input implementation details into the focus zone -- if we're considering focusing a subclass of `RCTBaseTextInputView`, we'll instead use the containing `backedTextInputView`. Testing: * TI inside FZ is now properly focused (using the new case added to the FZ page) * Verified all other cases on the FZ page * Verified in the downstream scenario that prompted this investigation Notes: * I noticed that Shift+Ctrl+Tab does not move focus out of the containing FZ, but that has been determined to be a pre-existing issue, and thus isn't being addressed in this change.
10 tasks
nakambo
added a commit
that referenced
this pull request
Jan 29, 2025
* Fix TextInput focus when inside a FocusZone When a TextInput is not inside a FocusZone, it properly participates in the key view loop in that Tab\Shift+Tab will place focus on the inner `RCTUITextView`, instead of the outer `RCTBaseTextInputView` subclass. This is due to [overriding](https://github.com/microsoft/react-native-macos/blob/b7033b3513d98b20a08ec20abfe2b9bb712c68d4/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm#L1147C1-L1150C2) the `canBecomeKeyView` in that base class. However, the FocusZone control does not look at that property -- instead it only considers `canBecomeFirstResponder`, as seen in #2329. Although it seems like the logical next step to use `canBecomeKeyView` in the FocusZone, that was previously done with #2267 but later reverted in #2322 since it broke things downstream. Instead, we'll make a compromise and leak some of the text input implementation details into the focus zone -- if we're considering focusing a subclass of `RCTBaseTextInputView`, we'll instead use the containing `backedTextInputView`. Testing: * TI inside FZ is now properly focused (using the new case added to the FZ page) * Verified all other cases on the FZ page * Verified in the downstream scenario that prompted this investigation Notes: * I noticed that Shift+Ctrl+Tab does not move focus out of the containing FZ, but that has been determined to be a pre-existing issue, and thus isn't being addressed in this change.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Platforms Impacted
Description of changes
This change allows FocusZone to make Menu always focusable on macOS, regardless of the user's system preference. This matches what native macOS Context menus do.
Verification
Tested turning the system setting on and off, and verified that you could still keyboard through a menu.
Pull request checklist
This PR has considered (when applicable):