Skip to content

Wrong cursor position on component update #260

Description

@tomegz

I'm using formatted number from onPhoneNumberChange to be value of the input. The cursor position is fine when formatted number is exactly the same as input, but when the formatted number is different than the value, then cursor is misplaced.

Live minimal example here: https://tomegz.github.io/react-intl-tel-input-cursor-example/

Code:

class App extends Component {
  constructor(props) {
    super(props)
    this.state = {
      value: '',
      infoVisible: false,
    }
    this.onPhoneNumberChange = this.onPhoneNumberChange.bind(this)
  }

  onPhoneNumberChange(isValid, value, countryData, number) {
    this.setState({
      value: number,
      infoVisible: value !== number
    })
  }

  render() {
    const { value, infoVisible } = this.state
    return (
      <div className="container">
        <p>Type here:</p>
        <IntlTelInput
          css={['intl-tel-input', 'form-control']}
          value={value}
          onPhoneNumberChange={this.onPhoneNumberChange}
        />
        {infoVisible && <p style={{ position: 'absolute', color: 'red', top: '30px' }}>Cursor position just broke!</p>}
      </div>
    );
  }
}

I submitted #261 to fix this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions