-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Problem when input type changes from email to text #12062
Comments
Dang. Just a gut triage, I think this is happening because React is trying to restore selection before the input actually changes types. For what ever reason, email and number inputs do not support the text selection API. There's an order of operations here that is out of sync. Great catch! |
Circling back! Thanks for providing a possible fix!
var input = document.createElement('input')
input.selectionStart // 0
input.type = 'email'
input.selectionStart // null
input.selectionEnd // null
Is that something you'd like to take on? |
Sorry, I was a little bit busy. I don't know when I can free some time to implement a proper fix with tests. |
I can pick this up! Would that be ok @adrianimboden? |
@leonascimento regarding the tests, any idea where could they be located? If there aren't any tests for Otherwise, if we want to test this on a more integration level, should we extend |
Hiii me nasir... Anyone needs help
nasir
…On Jan 24, 2018 8:30 PM, "Nathan Hunzaker" ***@***.***> wrote:
Circling back! Thanks for providing a possible fix!
1. I want to make sure that checking the type is sufficient. Should we
instead compare the value of selectionStart? For example:
var input = document.createElement('input')input.selectionStart // 0
input.type = 'email'input.selectionStart // nullinput.selectionEnd // null
1. From there, it would be awesome to make a DOM test fixture
<https://github.com/facebook/react/tree/master/fixtures/dom>
Is that something you'd like to take on?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#12062 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Aa65fYbFhhfN1XtW_1gYnmFexzBXsPl6ks5tN0WBgaJpZM4RlgsG>
.
|
Hi @Nasir13! I am currently working on this issue. I mention it so we don't end up doing duplicate work! |
Awesome. @spirosikmd thanks for picking this up! |
When an email input was replaced by a disabled text input on the same DOM position, an error would occur when trying to `setSelection`. The reason was that in `getSelectionInformation` the `selectionRange` was set to `null` as `hasSelectionCapabilities` was returning `false` for an `email` input type. `email` and `tel` input types do have selection capabilities, so in that case, `hasSelectionCapabilities` should return `true`.
When an email input was replaced by a disabled text input on the same DOM position, an error would occur when trying to `setSelection`. The reason was that in `getSelectionInformation` the `selectionRange` was set to `null` as `hasSelectionCapabilities` was returning `false` for an `email` input type. `email` and `tel` input types do have selection capabilities, so in that case, `hasSelectionCapabilities` should return `true`.
When an email input was replaced by a disabled text input on the same DOM position, an error would occur when trying to `setSelection`. The reason was that in `getSelectionInformation` the `selectionRange` was set to `null` as `hasSelectionCapabilities` was returning `false` for an `email` input type. `email` and `tel` input types do have selection capabilities, so in that case, `hasSelectionCapabilities` should return `true`.
When an email input was replaced by a disabled text input on the same DOM position, an error would occur when trying to `setSelection`. The reason was that in `getSelectionInformation` the `selectionRange` was set to `null` as `hasSelectionCapabilities` was returning `false` for an `email` input type. `email` and `tel` input types do have selection capabilities, so in that case, `hasSelectionCapabilities` should return `true`.
When an email input was replaced by a disabled text input on the same DOM position, an error would occur when trying to `setSelection`. The reason was that in `getSelectionInformation` the `selectionRange` was set to `null` as `hasSelectionCapabilities` was returning `false` for an `email` input type. `email` and `tel` input types do have selection capabilities, so in that case, `hasSelectionCapabilities` should return `true`.
`restoreSelection` did not account for input elements that have changed type after the commit phase. The new `text` input supported selection but the old `email` did not and `setSelection` was incorrectly trying to restore `null` selection state. We also extend input type check in selection capabilities to cover cases where input type is `search`, `tel`, `url`, or `password`.
Somebody working on this? The PR is quiet. If you want i can take it! @aweary @spirosikmd |
Hi @diegoborda! I am still waiting for an answer from @aweary on #12135. It should be ready to merge. |
`restoreSelection` did not account for input elements that have changed type after the commit phase. The new `text` input supported selection but the old `email` did not and `setSelection` was incorrectly trying to restore `null` selection state. We also extend input type check in selection capabilities to cover cases where input type is `search`, `tel`, `url`, or `password`.
`restoreSelection` did not account for input elements that have changed type after the commit phase. The new `text` input supported selection but the old `email` did not and `setSelection` was incorrectly trying to restore `null` selection state. We also extend input type check in selection capabilities to cover cases where input type is `search`, `tel`, `url`, or `password`.
`restoreSelection` did not account for input elements that have changed type after the commit phase. The new `text` input supported selection but the old `email` did not and `setSelection` was incorrectly trying to restore `null` selection state. We also extend input type check in selection capabilities to cover cases where input type is `search`, `tel`, `url`, or `password`.
* Do not set selection when prior selection is undefined (#12062) `restoreSelection` did not account for input elements that have changed type after the commit phase. The new `text` input supported selection but the old `email` did not and `setSelection` was incorrectly trying to restore `null` selection state. We also extend input type check in selection capabilities to cover cases where input type is `search`, `tel`, `url`, or `password`. * Add link to HTML spec for element types and selection * Add reset button to ReplaceEmailInput This commit adds a button to restore the original state of the ReplaceEmailInput fixture so that it can be run multiple times without refreshing the page.
Fixed in React 16.4.1. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When an input field changes from "email" to "text", an exception TypeError will be thrown from setSelection.
Reproduction
See here: https://github.com/adrianimboden/react-bug-reproduction
What is the expected behavior?
It should not crash because of an uncaught exception
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
master (4ca7855)
Firefox
This would be my proposed change to fix the issue: adrianimboden@db923b8
The text was updated successfully, but these errors were encountered: