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

Input type email bug #14168

Open
dominicarrojado opened this issue Nov 9, 2018 · 12 comments
Open

Input type email bug #14168

dominicarrojado opened this issue Nov 9, 2018 · 12 comments

Comments

@dominicarrojado
Copy link

https://codepen.io/anon/pen/GwZeNO

Open this codepen and paste this "[email protected] 1"
Then press backspace, notice that the focus changes to the beginning of the input.

@Xizario
Copy link

Xizario commented Nov 9, 2018

It happens because the browser trim the spaces from the end of the value. Modify your code as follows to see what happens:

  inputOnChange = ({ target }) => {
    console.log('\'' + target.value + '\'');
    this.setState({ [target.name]: target.value });
  }

Looks already discussed here #6368

@deammer
Copy link

deammer commented Nov 15, 2018

This means we have to choose between using an uncontrolled input with type="email" or a controlled input with type="text", which isn't great.

My "solution" is to swallow the event if it's a space:

// Controlled email input
<input
  type="email"
  value={this.state.value}
  onChange={this.onChange}
  onKeyPress={this.onKeyPress} />

onKeyPress = syntheticEvent => {
  if (syntheticEvent.charCode === 32) {
    syntheticEvent.preventDefault();
  }
}

onChange = evt => {
  this.setState({ value: evt.target.value });
}

This won't work if a user pastes an email with a space in it, but it's the least terrible bandaid I could come up with 🙈

@oliviertassinari
Copy link
Contributor

A similar issue was reported on Material-UI side. The regression seems to have come between React v16.2.0 and v16.3.0: https://codesandbox.io/s/xrv5w1j90w.

@nataliemarleny
Copy link

nataliemarleny commented Apr 20, 2019

I've narrowed down to where this problem was introduced - it first appears because of the changes in 4338c8db commit to the file src/renderers/dom/shared/HTMLDOMPropertyConfig.js. If the changes from this commit/file are reverted in any of the commits that come after it, <input type="email"> no longer has this strange behaviour.

As I can see in packages/react-dom/src/shared/DOMProperty.js in the master branch, there aren't any markers to denote that a prop has side-effects anymore, so purely reverting to fix this problem doesn't seem straightforward.

DASenkiv pushed a commit to ONLYOFFICE/DocSpace that referenced this issue Oct 31, 2019
@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@LucasDachman
Copy link

I'm still getting this bug on React 16.12.0

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Jan 14, 2020
@Avadakedvr
Copy link

I'm still getting this bug on React 16.12.0

same here, any fixes?

@josepharhar
Copy link
Contributor

I made a fix in chrome which should fix this problem which should be released in chrome 85, try it out on canary: https://www.google.com/chrome/canary/

@appxhive
Copy link

appxhive commented Jul 4, 2020

Hi, I'm still seeing this issue on React v16.13.1. Seeing it on Chrome browser. Anyone here observed the same on the latest React version 16.13.1? Someone here has the fix for this issue? Thanks.

@josepharhar
Copy link
Contributor

@JCC13 Did you try it in chrome canary? The fix is not in stable chrome yet.

@josepharhar
Copy link
Contributor

@gaearon I believe this issue is fixed.

  • Firefox: I believe this never affected firefox
  • Chrome: The fix is now in stable chrome
  • Safari: I just landed a fix to webkit

@deammer
Copy link

deammer commented Nov 6, 2020

@josepharhar I can confirm that this bug is fixed in Chrome 86 with React 16.13.1.

https://codepen.io/deammer/pen/rNLZzyV

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

No branches or pull requests

10 participants