1
1
/* eslint-disable react/no-find-dom-node, react/no-string-refs */
2
2
import React from 'react' ;
3
3
import PropTypes from 'prop-types' ;
4
- import ReactDOM from 'react-dom' ;
5
4
import { CSSTransition , TransitionGroup } from 'react-transition-group' ;
6
5
import _ from 'lodash' ;
7
6
import { injectIntl } from 'react-intl' ;
@@ -27,6 +26,13 @@ class CommentForm extends BaseComponent {
27
26
comment : emptyComment ,
28
27
} ;
29
28
29
+ this . horizontalAuthorRef = React . createRef ( ) ;
30
+ this . horizontalTextRef = React . createRef ( ) ;
31
+ this . stackedAuthorRef = React . createRef ( ) ;
32
+ this . stackedTextRef = React . createRef ( ) ;
33
+ this . inlineAuthorRef = React . createRef ( ) ;
34
+ this . inlineTextRef = React . createRef ( ) ;
35
+
30
36
_ . bindAll ( this , [ 'handleSelect' , 'handleChange' , 'handleSubmit' , 'resetAndFocus' ] ) ;
31
37
}
32
38
@@ -40,22 +46,20 @@ class CommentForm extends BaseComponent {
40
46
switch ( this . state . formMode ) {
41
47
case 0 :
42
48
comment = {
43
- author : ReactDOM . findDOMNode ( this . refs . horizontalAuthorNode ) . value ,
44
- text : ReactDOM . findDOMNode ( this . refs . horizontalTextNode ) . value ,
49
+ author : this . horizontalAuthorRef . current . value ,
50
+ text : this . horizontalTextRef . current . value ,
45
51
} ;
46
52
break ;
47
53
case 1 :
48
54
comment = {
49
- author : ReactDOM . findDOMNode ( this . refs . stackedAuthorNode ) . value ,
50
- text : ReactDOM . findDOMNode ( this . refs . stackedTextNode ) . value ,
55
+ author : this . stackedAuthorRef . current . value ,
56
+ text : this . stackedTextRef . current . value ,
51
57
} ;
52
58
break ;
53
59
case 2 :
54
60
comment = {
55
- // This is different because the input is a native HTML element
56
- // rather than a React element.
57
- author : ReactDOM . findDOMNode ( this . refs . inlineAuthorNode ) . value ,
58
- text : ReactDOM . findDOMNode ( this . refs . inlineTextNode ) . value ,
61
+ author : this . inlineAuthorRef . current . value ,
62
+ text : this . inlineTextRef . current . value ,
59
63
} ;
60
64
break ;
61
65
default :
@@ -81,13 +85,13 @@ class CommentForm extends BaseComponent {
81
85
let ref ;
82
86
switch ( this . state . formMode ) {
83
87
case 0 :
84
- ref = ReactDOM . findDOMNode ( this . refs . horizontalTextNode ) ;
88
+ ref = this . horizontalTextRef . current ;
85
89
break ;
86
90
case 1 :
87
- ref = ReactDOM . findDOMNode ( this . refs . stackedTextNode ) ;
91
+ ref = this . stackedTextRef . current ;
88
92
break ;
89
93
case 2 :
90
- ref = ReactDOM . findDOMNode ( this . refs . inlineTextNode ) ;
94
+ ref = this . inlineTextRef . current ;
91
95
break ;
92
96
default :
93
97
throw new Error ( `Unexpected state.formMode ${ this . state . formMode } ` ) ;
@@ -103,31 +107,31 @@ class CommentForm extends BaseComponent {
103
107
< hr />
104
108
< form className = "form-horizontal flex flex-col gap-4" onSubmit = { this . handleSubmit } >
105
109
< div className = "flex flex-col gap-0 items-center lg:gap-4 lg:flex-row" >
106
- < label htmlFor = "horizontalAuthorNode " className = "w-full lg:w-2/12 lg:text-end shrink-0" >
110
+ < label htmlFor = "horizontalAuthorRef " className = "w-full lg:w-2/12 lg:text-end shrink-0" >
107
111
{ formatMessage ( defaultMessages . inputNameLabel ) }
108
112
</ label >
109
113
< input
110
114
type = "text"
111
- id = "horizontalAuthorNode "
115
+ id = "horizontalAuthorRef "
112
116
placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
113
117
className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
114
- ref = "horizontalAuthorNode"
118
+ ref = { this . horizontalAuthorRef }
115
119
value = { this . state . comment . author }
116
120
onChange = { this . handleChange }
117
121
disabled = { this . props . isSaving }
118
122
/>
119
123
</ div >
120
124
121
125
< div className = "flex flex-col gap-0 items-center lg:gap-4 lg:flex-row" >
122
- < label htmlFor = "horizontalTextNode " className = "w-full lg:w-2/12 lg:text-end shrink-0" >
126
+ < label htmlFor = "horizontalTextRef " className = "w-full lg:w-2/12 lg:text-end shrink-0" >
123
127
{ formatMessage ( defaultMessages . inputTextLabel ) }
124
128
</ label >
125
129
< input
126
130
type = "textarea"
127
- id = "horizontalTextNode "
131
+ id = "horizontalTextRef "
128
132
placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
129
133
className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
130
- ref = "horizontalTextNode"
134
+ ref = { this . horizontalTextRef }
131
135
value = { this . state . comment . text }
132
136
onChange = { this . handleChange }
133
137
disabled = { this . props . isSaving }
@@ -158,31 +162,31 @@ class CommentForm extends BaseComponent {
158
162
< hr />
159
163
< form className = "flex flex-col gap-4" onSubmit = { this . handleSubmit } >
160
164
< div className = "flex flex-col gap-0" >
161
- < label htmlFor = "stackedAuthorNode " className = "w-full" >
165
+ < label htmlFor = "stackedAuthorRef " className = "w-full" >
162
166
{ formatMessage ( defaultMessages . inputNameLabel ) }
163
167
</ label >
164
168
< input
165
169
type = "text"
166
- id = "stackedAuthorNode "
170
+ id = "stackedAuthorRef "
167
171
placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
168
172
className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
169
- ref = "stackedAuthorNode"
173
+ ref = { this . stackedAuthorRef }
170
174
value = { this . state . comment . author }
171
175
onChange = { this . handleChange }
172
176
disabled = { this . props . isSaving }
173
177
/>
174
178
</ div >
175
179
176
180
< div className = "flex flex-col gap-0" >
177
- < label htmlFor = "stackedTextNode " className = "w-full" >
181
+ < label htmlFor = "stackedTextRef " className = "w-full" >
178
182
{ formatMessage ( defaultMessages . inputTextLabel ) }
179
183
</ label >
180
184
< input
181
185
type = "text"
182
- id = "stackedTextNode "
186
+ id = "stackedTextRef "
183
187
placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
184
188
className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
185
- ref = "stackedTextNode"
189
+ ref = { this . stackedTextRef }
186
190
value = { this . state . comment . text }
187
191
onChange = { this . handleChange }
188
192
disabled = { this . props . isSaving }
@@ -213,27 +217,27 @@ class CommentForm extends BaseComponent {
213
217
< hr />
214
218
< form className = "form-inline flex flex-col lg:flex-row flex-wrap gap-4" onSubmit = { this . handleSubmit } >
215
219
< div className = "flex gap-2 items-center" >
216
- < label htmlFor = "inlineAuthorNode " > { formatMessage ( defaultMessages . inputNameLabel ) } </ label >
220
+ < label htmlFor = "inlineAuthorRef " > { formatMessage ( defaultMessages . inputNameLabel ) } </ label >
217
221
< input
218
222
type = "text"
219
- id = "inlineAuthorNode "
223
+ id = "inlineAuthorRef "
220
224
placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
221
225
className = "px-3 py-1 leading-4 border border-gray-300 rounded"
222
- ref = "inlineAuthorNode"
226
+ ref = { this . inlineAuthorRef }
223
227
value = { this . state . comment . author }
224
228
onChange = { this . handleChange }
225
229
disabled = { this . props . isSaving }
226
230
/>
227
231
</ div >
228
232
229
233
< div className = "flex gap-2 items-center" >
230
- < label htmlFor = "inlineTextNode " > { formatMessage ( defaultMessages . inputTextLabel ) } </ label >
234
+ < label htmlFor = "inlineTextRef " > { formatMessage ( defaultMessages . inputTextLabel ) } </ label >
231
235
< input
232
236
type = "textarea"
233
- id = "inlineTextNode "
237
+ id = "inlineTextRef "
234
238
placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
235
239
className = "px-3 py-1 leading-4 border border-gray-300 rounded"
236
- ref = "inlineTextNode"
240
+ ref = { this . inlineTextRef }
237
241
value = { this . state . comment . text }
238
242
onChange = { this . handleChange }
239
243
disabled = { this . props . isSaving }
0 commit comments