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

TextInput: long text results in linebreak #2581

Closed
Hektar90 opened this issue Mar 3, 2021 · 25 comments · Fixed by #4261
Closed

TextInput: long text results in linebreak #2581

Hektar90 opened this issue Mar 3, 2021 · 25 comments · Fixed by #4261

Comments

@Hektar90
Copy link

Hektar90 commented Mar 3, 2021

Current behaviour

Typing a long text in TextInput and unfocusing it breaks the line

Expected behaviour

Text is cut off at the end and is only visible by scrolling while editing

Code sample

Bildschirmfoto 2021-03-03 um 18 39 29

Screenshots (if applicable)

Bildschirmfoto 2021-03-03 um 18 47 24

What have you tried

set numberOfLines to 1 and multiline to false

Your Environment

software version
ios or android ios
react-native 0.63.4
react-native-paper 4.7.2
node 12.14.0
npm 6.13.4
expo -
@github-actions
Copy link

github-actions bot commented Mar 3, 2021

Couldn't find version numbers for the following packages in the issue:

  • react-native-vector-icons
  • expo

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • npm (found: 6.13.4, latest: 7.6.0)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@dingziqi
Copy link

dingziqi commented Mar 4, 2021

It seems to be caused by the textAlign, only when textAlign: default, the ellipsis will work corectly。This is the bug of react-native, see the issues.

You can passdown textAlign: 'auto' to fixed it.

@Hektar90
Copy link
Author

Hektar90 commented Mar 4, 2021

It seems to be caused by the textAlign, only when textAlign: default, the ellipsis will work corectly。This is the bug of react-native, see the issues.

You can passdown textAlign: 'auto' to fixed it.

Unfortunately this is not working. Either adding textAlign:'auto' | 'left' | 'right' nor leaving the property out to take the default has no effect (#2445 I am using the latest paper version).
The latter leads to an type error saying textAlign needs to be set (see #2558).

EDIT: I've added textAlign: 'auto' in the style and this fixed the issue. First I thought you mean the textAlign property of TextInput. Now it's clear for others i hope.

@shllg
Copy link

shllg commented May 17, 2021

I my case textAlign: 'auto' does not work.

Additionally, I recognized the following behavior in development:

  • changing the vertical padding will "adjust" the component correctly. The ellipsis is still missing but the content is in one line
  • entering any text and remove it again results again in line breaks

Initially, it renders correctly (except of missing ellipsis) and changes result in line breaks.

@mohamedanwer123
Copy link

This issue still occur

@lirimkrosa
Copy link

In my case textAlign={undefined} it works!

@ghost
Copy link

ghost commented Jun 6, 2022

Still reproduce such issue

@joaoVictorDeAndrade
Copy link

In my case textAlign={"auto"} works, but the placeholder is no longer centered

@LorianAtashi01
Copy link

For people that use styled-components together with react-native-paper just add into your styling text-align: auto and it works:

const StyledInput = styled(TextInput)" background-color: transparent; text-align: auto;"

@ademagic
Copy link

ademagic commented Jul 11, 2023

Still seeing this issue. Adding textAlign: 'auto' or textAlign: undefined to the styles of the TextInput component doesn't seem to make a difference. I can see the textAlign property working with other values, but "auto" (or any other value) doesn't fix it.

@VictorioMolina
Copy link
Contributor

Same here

@simonbengtsson
Copy link

For me adding textAlign: 'auto' works.

Only <TextInput />:

Screenshot 2023-09-17 at 17 02 35

With fix: <TextInput style={{ textAlign: 'auto' }} />

Screenshot 2023-09-17 at 17 04 16

@Manasa2903
Copy link

Manasa2903 commented Nov 9, 2023

Not working with textAlign: 'auto', undefined. Tried as a prop for TextInput as well as in 'style'. Tried in ios simulator

@bleedweedsuz
Copy link

I tried this still not working:

<TextInput label={label} placeholder={placeholder} style={[{textAlign: 'auto'}, style ]} onChangeText={onChangeText} value={value?.toString()} />

Screenshot 2023-11-14 at 2 08 14 PM

@aannaassalam
Copy link

It seems to be caused by the textAlign, only when textAlign: default, the ellipsis will work corectly。This is the bug of react-native, see the facebook/react-native#29068 (comment).
You can passdown textAlign: 'auto' to fixed it.

Hi, I have figured it out. If some else thinks that this solution is not working for you then try using it with textAlignVertical="auto" coz this, is what worked for me.

@bleedweedsuz
Copy link

bleedweedsuz commented Nov 16, 2023

@aannaassalam which version u are using coz i am using ( "react-native-paper": "^5.11.1") it's not working.
My current code which i tried:
<TextInput textAlignVertical='auto' multiline={false} numberOfLines={1} label={label} placeholder={placeholder} mode={mode} style={[{textAlign: undefined, overflow:'hidden'}, style ]} onChangeText={onChangeText} value={value?.toString()} right={right} />

i am using overflow hidden to make useable currently it look like in the example image.
Screenshot 2023-11-16 at 6 36 12 PM

Edit: after i did some tinkering, this issue only occur in mode={"outlined"} ; flat is working fine.

@m4rv4ul3r
Copy link

This bug occurs on IOS in my case. On android it seems to be rendered correct. I tried it on IOS simulator and IOS physical device as well. Both are showing the bug. So it seems to be an IOS issue.

@aannaassalam
Copy link

@aannaassalam which version u are using coz i am using ( "react-native-paper": "^5.11.1") it's not working. My current code which i tried: <TextInput textAlignVertical='auto' multiline={false} numberOfLines={1} label={label} placeholder={placeholder} mode={mode} style={[{textAlign: undefined, overflow:'hidden'}, style ]} onChangeText={onChangeText} value={value?.toString()} right={right} />

i am using overflow hidden to make useable currently it look like in the example image. Screenshot 2023-11-16 at 6 36 12 PM

Edit: after i did some tinkering, this issue only occur in mode={"outlined"} ; flat is working fine.

Yes, you should pass it to style prop instead of passing it to the component and again there was a mistake in my comment textAlignVertical is not the correct way to do that.

@aannaassalam
Copy link

Here is my piece of working code -

<TextInput onChangeText={onChange} outlineColor="#268C43" underlineColorAndroid="transparent" activeOutlineColor="#268C43" mode="outlined" outlineStyle={{ borderRadius: 10, }} label={ <Text style={{ fontSize: 16 / fontScale, textTransform: 'capitalize', }}> {t('address')} </Text> } value={value} style={styles.textInput} placeholder={t('address')} placeholderTextColor={'#333'} keyboardType="default" editable={false} right={ <TextInput.Icon icon="crosshairs-gps" size={24} color="#268C43" onPress={getLocation} /> } />

Styles:

textInput: { backgroundColor: '#fff', fontFamily: 'ubuntu-medium', fontSize: 16 / fontScale, textAlign: 'auto', },

@mertcankose
Copy link

error still exist

@danielle-cruz
Copy link

Same error on iOS

@truonghoangpham123
Copy link

Same error on iOS

Have you solved the problem yet? You can use:

inputStyle: {
    textAlign: 'auto',
    lineHeight: undefined,
}

I think it can help you solve the problem!

@bleedweedsuz
Copy link

if this issue still exist for single line Textinput then use this code
Trick is u need to set height for non multiline. issue only in iOS. It try to accommodate the overflowing text that is why, this error
React-native-paper: version 5.11.4

Code and demo of Before and After
Before:
Screenshot 2023-12-25 at 3 21 59 PM
<TextInput mode='outlined' value='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ut cursus orci. Fusce condimentum leo id facilisis porttitor.'/>

After:
Screenshot 2023-12-25 at 3 53 45 PM

<TextInput style={{ height: 56 }} mode='outlined' value='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ut cursus orci. Fusce condimentum leo id facilisis porttitor.'/>

Note: 56 is default height for outlined

@truonghoangpham123
Copy link

if this issue still exist for single line Textinput then use this code Trick is u need to set height for non multiline. issue only in iOS. It try to accommodate the overflowing text that is why, this error React-native-paper: version 5.11.4

Code and demo of Before and After Before: Screenshot 2023-12-25 at 3 21 59 PM <TextInput mode='outlined' value='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ut cursus orci. Fusce condimentum leo id facilisis porttitor.'/>

After: Screenshot 2023-12-25 at 3 53 45 PM

<TextInput style={{ height: 56 }} mode='outlined' value='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ut cursus orci. Fusce condimentum leo id facilisis porttitor.'/>

Note: 56 is default height for outlined

Yep, your results are still correct but in terms of UX, it doesn't seem very good.
The desired result is shown below.

Before:
Screenshot 2023-12-25 at 17 57 15

After:
Screenshot 2023-12-25 at 17 57 22

However your results are missing truncated

@john-trieu-nguyen
Copy link
Contributor

john-trieu-nguyen commented Jan 8, 2024

Ran into the same issue when I updated the react-native-paper library.
Found a bug in release 5.10.5 that broke existing behaivour.

Have submitted a pull request #4261 which has fixed it.

Fixed as of 5.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.