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

Fix TextInput focus when inside a FocusZone #3849

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { View, ScrollView, Pressable } from 'react-native';
import { View, ScrollView, Pressable, TextInput } from 'react-native';

import type { FocusZoneDirection, FocusZoneTabNavigation } from '@fluentui/react-native';
import { FocusZone, MenuButton, Text, useOnPressWithFocus } from '@fluentui/react-native';
Expand Down Expand Up @@ -207,6 +207,19 @@ const FocusZoneGrid: React.FunctionComponent = () => {
);
};

const FocusZoneTextInput: React.FunctionComponent = () => {
return (
<FocusZoneListWrapper>
<>
<Text>FocusZone Grid</Text>
<FocusZone>
<TextInput multiline={true} />
</FocusZone>
</>
</FocusZoneListWrapper>
);
};

const focusZoneSections: TestSection[] = [
{
name: 'Common FocusZone Usage',
Expand Down Expand Up @@ -245,6 +258,10 @@ const focusZoneSections: TestSection[] = [
name: 'FocusZone Grid',
component: FocusZoneGrid,
},
{
name: 'FocusZone with TextInput',
component: FocusZoneTextInput,
},
];

const e2eSections: TestSection[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix TextInput focus when inside a FocusZone",
"packageName": "@fluentui-react-native/focus-zone",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add TextInput inside FocusZone case",
"packageName": "@fluentui-react-native/tester",
"email": "[email protected]",
"dependentChangeType": "patch"
}
10 changes: 9 additions & 1 deletion packages/components/FocusZone/macos/RCTFocusZone.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "KeyCodes.h"
#import <React/RCTBaseTextInputView.h>
#import "RCTFocusZone.h"
#import "RCTi18nUtil.h"

Expand Down Expand Up @@ -61,7 +62,14 @@ static inline CGFloat GetMinDistanceBetweenRectVerticesAndPoint(NSRect rect, NSP

for (NSView *view in [parentView subviews]) {
if ([view acceptsFirstResponder]) {
return view;
if ([view isKindOfClass:[RCTBaseTextInputView class]]) {
RCTUIView *backedTextInputView = [(RCTBaseTextInputView *)view backedTextInputView];
if ([backedTextInputView acceptsFirstResponder]) {
return backedTextInputView;
}
} else {
return view;
}
}

NSView *match = GetFirstFocusableViewWithin(view);
Expand Down