File tree Expand file tree Collapse file tree
fixtures/dom/src/components/fixtures/text-inputs
packages/react-dom/src/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Fixture from '../../Fixture' ;
2+
3+ const React = window . React ;
4+
5+ class ReplaceEmailInput extends React . Component {
6+ state = {
7+ formSubmitted : false ,
8+ } ;
9+
10+ render ( ) {
11+ return (
12+ < Fixture >
13+ < form
14+ className = "control-box"
15+ onSubmit = { event => {
16+ event . preventDefault ( ) ;
17+ this . setState ( { formSubmitted : true } ) ;
18+ } } >
19+ < fieldset >
20+ < legend > Email</ legend >
21+ { ! this . state . formSubmitted ? (
22+ < input type = "email" />
23+ ) : (
24+ < input type = "text" disabled = { true } />
25+ ) }
26+ </ fieldset >
27+ </ form >
28+ </ Fixture >
29+ ) ;
30+ }
31+ }
32+
33+ export default ReplaceEmailInput ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import Fixture from '../../Fixture';
22import FixtureSet from '../../FixtureSet' ;
33import TestCase from '../../TestCase' ;
44import InputTestCase from './InputTestCase' ;
5+ import ReplaceEmailInput from './ReplaceEmailInput' ;
56
67const React = window . React ;
78
@@ -110,6 +111,21 @@ class TextInputFixtures extends React.Component {
110111 < InputTestCase type = "url" defaultValue = "" />
111112 </ TestCase >
112113
114+ < TestCase
115+ title = "Replacing email input with text disabled input"
116+ relatedIssues = "12062" >
117+ < TestCase . Steps >
118+ < li > Type "test@test.com"</ li >
119+ < li > Press enter</ li >
120+ </ TestCase . Steps >
121+
122+ < TestCase . ExpectedResult >
123+ There should be no selection-related error in the console.
124+ </ TestCase . ExpectedResult >
125+
126+ < ReplaceEmailInput />
127+ </ TestCase >
128+
113129 < TestCase title = "All inputs" description = "General test of all inputs" >
114130 < InputTestCase type = "text" defaultValue = "Text" />
115131 < InputTestCase type = "email" defaultValue = "user@example.com" />
Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ export function hasSelectionCapabilities(elem) {
2626 const nodeName = elem && elem . nodeName && elem . nodeName . toLowerCase ( ) ;
2727 return (
2828 nodeName &&
29- ( ( nodeName === 'input' && elem . type === 'text' ) ||
29+ ( ( nodeName === 'input' &&
30+ ( elem . type === 'text' ||
31+ elem . type === 'search' ||
32+ elem . type === 'tel' ||
33+ elem . type === 'url' ||
34+ elem . type === 'password' ) ) ||
3035 nodeName === 'textarea' ||
3136 elem . contentEditable === 'true' )
3237 ) ;
@@ -52,7 +57,10 @@ export function restoreSelection(priorSelectionInformation) {
5257 const priorFocusedElem = priorSelectionInformation . focusedElem ;
5358 const priorSelectionRange = priorSelectionInformation . selectionRange ;
5459 if ( curFocusedElem !== priorFocusedElem && isInDocument ( priorFocusedElem ) ) {
55- if ( hasSelectionCapabilities ( priorFocusedElem ) ) {
60+ if (
61+ priorSelectionRange !== null &&
62+ hasSelectionCapabilities ( priorFocusedElem )
63+ ) {
5664 setSelection ( priorFocusedElem , priorSelectionRange ) ;
5765 }
5866
You can’t perform that action at this time.
0 commit comments