Skip to content

Commit 3ac229a

Browse files
authored
[Fabric] Add caretHidden to TextInput (#12430)
* add caretHidden to Fabric's TextInput * Change files * feedback * feedback2 * add caretHidden to TextInput example page * lint and snapshot * update snapshot * revert snapshot * add componentTest
1 parent 04329dc commit 3ac229a

File tree

7 files changed

+97
-3
lines changed

7 files changed

+97
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "add caretHidden to Fabric's TextInput",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/tester/src/js/examples/TextInput/TextInputExample.windows.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,22 @@ const examples: Array<RNTesterModuleExample> = [
724724
return <SpellCheckSample />;
725725
},
726726
},
727+
{
728+
title: 'CaretHidden set to True',
729+
render: function (): React.Node {
730+
return (
731+
<View>
732+
<Text>CaretHidden</Text>
733+
<TextInput
734+
style={styles.singleLine}
735+
caretHidden={true}
736+
placeholder="caretHidden={true}"
737+
testID="textinput-carethidden"
738+
/>
739+
</View>
740+
);
741+
},
742+
},
727743
// Windows]
728744
];
729745

packages/e2e-test-app-fabric/test/TextInputComponentTest.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,10 @@ describe('TextInput Tests', () => {
641641
const dump = await dumpVisualTree('textinput-padding');
642642
expect(dump).toMatchSnapshot();
643643
});
644+
test('TextInputs can have caretHidden', async () => {
645+
const component = await app.findElementByTestID('textinput-carethidden');
646+
await component.waitForDisplayed({timeout: 5000});
647+
const dump = await dumpVisualTree('textinput-carethidden');
648+
expect(dump).toMatchSnapshot();
649+
});
644650
});

packages/e2e-test-app-fabric/test/__snapshots__/TextInputComponentTest.test.ts.snap

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3641,6 +3641,53 @@ exports[`TextInput Tests TextInputs can have attributed text 1`] = `
36413641
}
36423642
`;
36433643

3644+
exports[`TextInput Tests TextInputs can have caretHidden 1`] = `
3645+
{
3646+
"Automation Tree": {
3647+
"AutomationId": "textinput-carethidden",
3648+
"ControlType": 50004,
3649+
"HelpText": "caretHidden={true}",
3650+
"IsEnabled": true,
3651+
"IsKeyboardFocusable": true,
3652+
"LocalizedControlType": "edit",
3653+
"Name": "caretHidden={true}",
3654+
},
3655+
"Visual Tree": {
3656+
"Children": [
3657+
{
3658+
"Brush": {
3659+
"Brush Type": "ColorBrush",
3660+
"Color": "rgba(0, 0, 0, 255)",
3661+
},
3662+
"Offset": [
3663+
0,
3664+
0,
3665+
0,
3666+
],
3667+
"Opacity": 0,
3668+
"Size": [
3669+
0,
3670+
0,
3671+
],
3672+
"Visual Type": "SpriteVisual",
3673+
},
3674+
],
3675+
"Comment": "textinput-carethidden",
3676+
"Offset": [
3677+
0,
3678+
0,
3679+
0,
3680+
],
3681+
"Opacity": 1,
3682+
"Size": [
3683+
916,
3684+
23,
3685+
],
3686+
"Visual Type": "SpriteVisual",
3687+
},
3688+
}
3689+
`;
3690+
36443691
exports[`TextInput Tests TextInputs can have custom return key label, Compile 1`] = `
36453692
{
36463693
"Automation Tree": {
@@ -6643,4 +6690,4 @@ exports[`TextInput Tests Uncontrolled TextInput 1`] = `
66436690
"Visual Type": "SpriteVisual",
66446691
},
66456692
}
6646-
`;
6693+
`;

packages/e2e-test-app-fabric/test/__snapshots__/snapshotPages.test.js.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74799,6 +74799,24 @@ exports[`snapshotAllPages TextInput 36`] = `
7479974799
]
7480074800
`;
7480174801

74802+
exports[`snapshotAllPages TextInput 37`] = `
74803+
<View>
74804+
<Text>
74805+
CaretHidden
74806+
</Text>
74807+
<TextInput
74808+
caretHidden={true}
74809+
placeholder="caretHidden={true}"
74810+
style={
74811+
{
74812+
"fontSize": 16,
74813+
}
74814+
}
74815+
testID="textinput-carethidden"
74816+
/>
74817+
</View>
74818+
`;
74819+
7480274820
exports[`snapshotAllPages TextInputs with key prop 1`] = `
7480374821
<View>
7480474822
<TextInput

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ struct CompCaretVisual
10941094
}
10951095

10961096
private:
1097-
bool m_isVisible{false};
1097+
bool m_isVisible{true};
10981098
typename TTypeRedirects::SpriteVisual m_compVisual;
10991099
winrt::Microsoft::ReactNative::Composition::IVisual m_visual;
11001100
typename TTypeRedirects::ScalarKeyFrameAnimation m_opacityAnimation;

vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct CompTextHost : public winrt::implements<CompTextHost, ITextHost> {
161161

162162
//@cmember Show the caret
163163
BOOL TxShowCaret(BOOL fShow) override {
164-
m_outer->ShowCaret(fShow);
164+
m_outer->ShowCaret(m_outer->m_props->caretHidden ? false : fShow);
165165
return true;
166166
}
167167

0 commit comments

Comments
 (0)