File tree 4 files changed +173
-116
lines changed
fixtures/dom/src/components/fixtures/text-inputs
packages/react-dom/src/client
4 files changed +173
-116
lines changed 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';
2
2
import FixtureSet from '../../FixtureSet' ;
3
3
import TestCase from '../../TestCase' ;
4
4
import InputTestCase from './InputTestCase' ;
5
+ import ReplaceEmailInput from './ReplaceEmailInput' ;
5
6
6
7
const React = window . React ;
7
8
@@ -110,6 +111,21 @@ class TextInputFixtures extends React.Component {
110
111
< InputTestCase type = "url" defaultValue = "" />
111
112
</ TestCase >
112
113
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
+
113
129
< TestCase title = "All inputs" description = "General test of all inputs" >
114
130
< InputTestCase type = "text" defaultValue = "Text" />
115
131
< 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) {
26
26
const nodeName = elem && elem . nodeName && elem . nodeName . toLowerCase ( ) ;
27
27
return (
28
28
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' ) ) ||
30
35
nodeName === 'textarea' ||
31
36
elem . contentEditable === 'true' )
32
37
) ;
@@ -52,7 +57,10 @@ export function restoreSelection(priorSelectionInformation) {
52
57
const priorFocusedElem = priorSelectionInformation . focusedElem ;
53
58
const priorSelectionRange = priorSelectionInformation . selectionRange ;
54
59
if ( curFocusedElem !== priorFocusedElem && isInDocument ( priorFocusedElem ) ) {
55
- if ( hasSelectionCapabilities ( priorFocusedElem ) ) {
60
+ if (
61
+ priorSelectionRange !== null &&
62
+ hasSelectionCapabilities ( priorFocusedElem )
63
+ ) {
56
64
setSelection ( priorFocusedElem , priorSelectionRange ) ;
57
65
}
58
66
You can’t perform that action at this time.
0 commit comments