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's caret always move to beginning when toggling secureTextEntry #18377

Closed
williamliangwl opened this issue Mar 14, 2018 · 12 comments
Closed
Labels
Component: TextInput Related to the TextInput component. Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@williamliangwl
Copy link

I am using ReactNative v.0.52.0 and currently developing a TextInput for password, but want to enable user to show / hide their typed input. The problem when toggling the value of secureTextEntry, the caret always move to the beginning of the input.

I have only tested this in Android device.

Environment

Environment:

  • OS: Windows 10
  • Node: 6.11.5
  • Yarn: 1.3.2
  • npm: 4.6.1
  • Watchman: Not Found
  • Xcode: N/A
  • Android Studio: Version 3.0.0.0 AI-171.4443003

Packages: (wanted => installed)

  • react: 16.2.0 => 16.2.0
  • react-native: 0.52.0 => 0.52.0

Expected Behavior

I expect the caret will always stay at the end of the input, when toggling the secureTextEntry

Steps to Reproduce

I manage to reproduce this using a very simple code, I put it at the App.js

export default class App extends Component {

  constructor() {
    super();
    this.state = {
      showPassword: false
    };
  }

  toggleShow() {
    this.setState({
      showPassword: !this.state.showPassword
    });
  }

  render() {
    return (
      <View>
        <TextInput secureTextEntry={this.state.showPassword} />
        <Button title={'Toggle'} onPress={this.toggleShow.bind(this)} />
      </View>
    );
  }
}
@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest stable release?

Thank you for your contributions.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Old Version ⏪ Ran Commands One of our bots successfully processed a command. labels Mar 14, 2018
@williamliangwl
Copy link
Author

williamliangwl commented Mar 14, 2018

@react-native-bot Yes tested in v0.54.2 and still having same issue in Android device

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Component: TextInput Related to the TextInput component. labels Mar 16, 2018
@williamliangwl
Copy link
Author

I do realize that in version 0.54, a fix has been submitted, but it looks like not working although I test it using 0.54.2. The commit is 09b43e4

@react-native-bot react-native-bot added the Platform: Windows Building on Windows. label Mar 20, 2018
@williamliangwl
Copy link
Author

@react-native-bot I don't think Old Version label is still valid here as it is tested not working in v0.54.2 and I still can't find a solution for it

@hramos hramos removed the Platform: Windows Building on Windows. label Mar 29, 2018
@LiHaoTan
Copy link

LiHaoTan commented Jun 6, 2018

Is there a workaround for this? It does not appear the fix works like @williamliangwl mentioned.

EDIT: for now this is the workaround I am using:

  componentDidUpdate() {
    // workaround to allow TextInput to return to end of selection after toggling secureTextEntry
    if (this.state.previousInputValue) {
      this.setState({ inputValue: this.state.previousInputValue, previousInputValue: null });
    }
  }

  <Button
  onPress={() =>
      this.setState(previousState => ({
        isSecureTextEntry: !previousState.isSecureTextEntry,
        inputValue: '',
        previousInputValue: this.state.inputValue,
      }))
  }
>

@LcsLpr
Copy link

LcsLpr commented Jun 21, 2018

Same issue

@minhtamwebmaster
Copy link

same issue

@vitorsilvalima
Copy link

I have the same issue too

@creambyemute
Copy link

Yeah same issue here.

Tried on 0.54.0 up to 0.55.4 and it's apparent on all these versions. The fix from 09b43e4 did somehow not solve it.

onSelectionChange event is fired twice, first with the correct values and then with the wrong values (start: 0, end: 0).

If you instead write some text while secureTextEntry=false and then toggle secureTextEntry=true then the cursor stays at the correct position.
But when you then write something again and toggle, the cursor is reset again.

@jainkuniya
Copy link
Contributor

Hi, this issue will be fixed by #17990

@stale
Copy link

stale bot commented Dec 21, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 21, 2018
@stale
Copy link

stale bot commented Dec 28, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Dec 28, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: TextInput Related to the TextInput component. Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

9 participants