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: adjust initial placeholder text value #3331

Merged
merged 1 commit into from
Aug 31, 2022
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
12 changes: 10 additions & 2 deletions src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const TextInput = React.forwardRef<TextInputHandles, Props>(
);
const [focused, setFocused] = React.useState<boolean>(false);
const [placeholder, setPlaceholder] = React.useState<string | undefined>(
''
' '
);
const [uncontrolledValue, setUncontrolledValue] = React.useState<
string | undefined
Expand Down Expand Up @@ -304,7 +304,15 @@ const TextInput = React.forwardRef<TextInputHandles, Props>(
) as unknown as NodeJS.Timeout;
} else {
// hidePlaceholder
setPlaceholder('');

// Issue: https://github.com/callstack/react-native-paper/issues/3138
// Description: Changing the placeholder text value dynamically,
// within multiline input on iOS, doesn't work properly –
// the placeholder is not displayed initially.
// Root cause: Placeholder initial value, which has length 0.
// More context: The issue was also reproduced in react-native, using its own TextInput.
// Workaround: Set an empty space character in the default value.
setPlaceholder(' ');
}

return () => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/__tests__/TextInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ it('renders label with correct color when inactive', () => {
});
});

it('renders input placeholder initially with an empty space character', () => {
const { getByTestId } = render(
<TextInput multiline label="Multiline input" testID={'text-input'} />
);

expect(getByTestId('text-input-flat').props.placeholder).toBe(' ');
});

describe('maxFontSizeMultiplier', () => {
const createInput = (type, maxFontSizeMultiplier) => {
return (
Expand Down
12 changes: 6 additions & 6 deletions src/components/__tests__/__snapshots__/TextInput.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exports[`correctly applies a component as the text label 1`] = `
onBlur={[Function]}
onChangeText={[Function]}
onFocus={[Function]}
placeholder=""
placeholder=" "
placeholderTextColor="rgba(73, 69, 79, 1)"
selectionColor="rgba(103, 80, 164, 1)"
style={
Expand Down Expand Up @@ -349,7 +349,7 @@ exports[`correctly applies default textAlign based on default RTL 1`] = `
onBlur={[Function]}
onChangeText={[Function]}
onFocus={[Function]}
placeholder=""
placeholder=" "
placeholderTextColor="rgba(73, 69, 79, 1)"
selectionColor="rgba(103, 80, 164, 1)"
style={
Expand Down Expand Up @@ -584,7 +584,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
onBlur={[Function]}
onChangeText={[Function]}
onFocus={[Function]}
placeholder=""
placeholder=" "
placeholderTextColor="rgba(73, 69, 79, 1)"
selectionColor="rgba(103, 80, 164, 1)"
style={
Expand Down Expand Up @@ -770,7 +770,7 @@ exports[`correctly applies textAlign center 1`] = `
onBlur={[Function]}
onChangeText={[Function]}
onFocus={[Function]}
placeholder=""
placeholder=" "
placeholderTextColor="rgba(73, 69, 79, 1)"
selectionColor="rgba(103, 80, 164, 1)"
style={
Expand Down Expand Up @@ -957,7 +957,7 @@ exports[`correctly renders left-side icon adornment, and right-side affix adornm
onBlur={[Function]}
onChangeText={[Function]}
onFocus={[Function]}
placeholder=""
placeholder=" "
placeholderTextColor="rgba(73, 69, 79, 1)"
selectionColor="rgba(103, 80, 164, 1)"
style={
Expand Down Expand Up @@ -1311,7 +1311,7 @@ exports[`correctly renders left-side icon adornment, and right-side affix adornm
onBlur={[Function]}
onChangeText={[Function]}
onFocus={[Function]}
placeholder=""
placeholder=" "
placeholderTextColor="rgba(73, 69, 79, 1)"
selectionColor="rgba(103, 80, 164, 1)"
style={
Expand Down