Skip to content
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
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Added fix for AutoFocus",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
14 changes: 14 additions & 0 deletions packages/playground/Samples/textinput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ export default class Bootstrap extends React.Component<{}, any> {
placeholder="Focus and then click outside"
onEndEditing={this.handleEndEditing}
/>
<TextInput
style={[styles.input, {borderColor: 'green', borderWidth: 2}]}
placeholder={
'autoFocus: true - This input will be focused automatically'
}
autoFocus={true}
/>
<TextInput
style={[styles.input, {borderColor: 'red', borderWidth: 2}]}
placeholder={
'autoFocus: false - This input will NOT be focused automatically'
}
autoFocus={false}
/>

<KeyboardAvoidingView
style={styles.container}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,13 @@ void WindowsTextInputComponentView::onMounted() noexcept {
m_propBits |= TXTBIT_CHARFORMATCHANGE;
}
InternalFinalize();

// Handle autoFocus property - focus the component when mounted if autoFocus is true
if (windowsTextInputProps().autoFocus) {
if (auto root = rootComponentView()) {
root->TrySetFocusedComponent(*get_strong(), winrt::Microsoft::ReactNative::FocusNavigationDirection::None);
}
}
}

std::optional<std::string> WindowsTextInputComponentView::getAccessiblityValue() noexcept {
Expand Down
Loading