-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`.
- Loading branch information
1 parent
6bf2797
commit b4993d7
Showing
4 changed files
with
173 additions
and
116 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
fixtures/dom/src/components/fixtures/text-inputs/ReplaceEmailInput.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Fixture from '../../Fixture'; | ||
|
||
const React = window.React; | ||
|
||
class ReplaceEmailInput extends React.Component { | ||
state = { | ||
formSubmitted: false, | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Fixture> | ||
<form | ||
className="control-box" | ||
onSubmit={event => { | ||
event.preventDefault(); | ||
this.setState({formSubmitted: true}); | ||
}}> | ||
<fieldset> | ||
<legend>Email</legend> | ||
{!this.state.formSubmitted ? ( | ||
<input type="email" /> | ||
) : ( | ||
<input type="text" disabled={true} /> | ||
)} | ||
</fieldset> | ||
</form> | ||
</Fixture> | ||
); | ||
} | ||
} | ||
|
||
export default ReplaceEmailInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import Fixture from '../../Fixture'; | |
import FixtureSet from '../../FixtureSet'; | ||
import TestCase from '../../TestCase'; | ||
import InputTestCase from './InputTestCase'; | ||
import ReplaceEmailInput from './ReplaceEmailInput'; | ||
|
||
const React = window.React; | ||
|
||
|
@@ -110,6 +111,21 @@ class TextInputFixtures extends React.Component { | |
<InputTestCase type="url" defaultValue="" /> | ||
</TestCase> | ||
|
||
<TestCase | ||
title="Replacing email input with text disabled input" | ||
relatedIssues="12062"> | ||
<TestCase.Steps> | ||
<li>Type "[email protected]"</li> | ||
<li>Press enter</li> | ||
</TestCase.Steps> | ||
|
||
<TestCase.ExpectedResult> | ||
There should be no selection-related error in the console. | ||
</TestCase.ExpectedResult> | ||
|
||
<ReplaceEmailInput /> | ||
</TestCase> | ||
|
||
<TestCase title="All inputs" description="General test of all inputs"> | ||
<InputTestCase type="text" defaultValue="Text" /> | ||
<InputTestCase type="email" defaultValue="[email protected]" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.