Skip to content

Commit

Permalink
[fix] Add support for caretHidden prop in TextInput
Browse files Browse the repository at this point in the history
Close #2542
Fix #2541
  • Loading branch information
aswin-s authored and necolas committed Jun 26, 2023
1 parent c350d82 commit 1c376db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/react-native-web-examples/pages/text-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export default function TextInputPage() {
rows={3}
style={styles.multiline}
/>
<TextInput
caretHidden
defaultValue="caretHidden"
style={styles.textinput}
/>
</View>
</Example>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ describe('components/TextInput', () => {
});
});

describe('prop "caretHidden"', () => {
test('value "true"', () => {
const { container } = render(<TextInput caretHidden />);
const style = window.getComputedStyle(container.firstChild);
expect(style.caretColor).toEqual('transparent');
});
});

describe('prop "clearTextOnFocus"', () => {
const defaultValue = 'defaultValue';

Expand Down
7 changes: 6 additions & 1 deletion packages/react-native-web/src/exports/TextInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const TextInput: React.AbstractComponent<
autoCompleteType,
autoCorrect = true,
blurOnSubmit,
caretHidden,
clearTextOnFocus,
dir,
editable,
Expand Down Expand Up @@ -402,7 +403,8 @@ const TextInput: React.AbstractComponent<
{ '--placeholderTextColor': placeholderTextColor },
styles.textinput$raw,
styles.placeholder,
props.style
props.style,
caretHidden && styles.caretHidden
];
supportedProps.type = multiline ? undefined : type;

Expand Down Expand Up @@ -448,6 +450,9 @@ const styles = StyleSheet.create({
},
placeholder: {
placeholderTextColor: 'var(--placeholderTextColor)'
},
caretHidden: {
caretColor: 'transparent'
}
});

Expand Down
1 change: 1 addition & 0 deletions packages/react-native-web/src/exports/TextInput/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type TextInputProps = {
autoCorrect?: ?boolean,
autoFocus?: ?boolean,
blurOnSubmit?: ?boolean,
caretHidden?: ?boolean,
clearTextOnFocus?: ?boolean,
defaultValue?: ?string,
dir?: ?('auto' | 'ltr' | 'rtl'),
Expand Down

0 comments on commit 1c376db

Please sign in to comment.