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

Visible text changes when assigning to input.defaultValue #5427

Closed
josepharhar opened this issue Apr 1, 2020 · 6 comments
Closed

Visible text changes when assigning to input.defaultValue #5427

josepharhar opened this issue Apr 1, 2020 · 6 comments

Comments

@josepharhar
Copy link
Contributor

In Chrome and Safari, but not Firefox, sanitization will apply in-place for number and email inputs when modifying the value attribute, via any of setAttribute('value', ...), removeAttribute('value'), and defaultValue = ....
In React, defaultValue is assigned every time the input event is fired on the input element in order to make the value attribute reflect what the controlling react component is. I made a minimal example of how this works here: https://value-attribute.glitch.me/

This works fine, but when the user enters something which would be modified by sanitization, the visible text will be swapped out and selection reset while the user is typing. You can see this behavior by going to my minimal example page above and typing something like " user@example.com" in the email input or "12e3" into the number input.
React has made workarounds for this behavior for number inputs by delaying assigning to defaultValue until the blur event, but they have not done so for email inputs and it has caused many issues in react:

I am guessing this behavior exists in chrome and safari to make it so that when the default value from the value attribute is used it is sanitized, but in this case the value attribute is not actually being used at all. I proposed adding the input.rawValue property to address this problem, but I think that changing this behavior to only change the visible text when we are actually using the default value would be a better fix, especially since Firefox already has the desired behavior. I made a WIP patch to do this in chrome here.

Is this behavior specced? Should it be specced?

cc @tkent-google @domenic @mfreed7

@tkent-google
Copy link
Collaborator

only change the visible text when we are actually using the default value would be a better fix

It seems the current Chrome/Safari behavior looks just an implementation bug, and we don't need to discuss it in WHATWG.

@josepharhar
Copy link
Contributor Author

Sweet! Thanks for the clarification!

@annevk
Copy link
Member

annevk commented Apr 2, 2020

Please do add web-platform-tests for this if there aren't any. E.g., this could be tested with reference tests I suspect.

@josepharhar
Copy link
Contributor Author

I like the reftest idea, I think its perfect.
Unfortunately I couldn't get test_driver.Actions() to type into the input elements for me...

@annevk
Copy link
Member

annevk commented May 14, 2020

@josepharhar file an issue at https://github.com/web-platform-tests/wpt/issues/new with some steps to reproduce? I'm sure they can help you.

@josepharhar
Copy link
Contributor Author

Coming back to this, I finally got the wpt to work, I just had to use test_driver.send_keys instead of test_driver.Actions. The fix and wpt will be merged soon

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

No branches or pull requests

3 participants