11/* eslint-disable react/no-find-dom-node, react/no-string-refs */
22import React from 'react' ;
33import PropTypes from 'prop-types' ;
4- import ReactDOM from 'react-dom' ;
54import { CSSTransition , TransitionGroup } from 'react-transition-group' ;
65import _ from 'lodash' ;
76import { injectIntl } from 'react-intl' ;
@@ -27,6 +26,13 @@ class CommentForm extends BaseComponent {
2726 comment : emptyComment ,
2827 } ;
2928
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+
3036 _ . bindAll ( this , [ 'handleSelect' , 'handleChange' , 'handleSubmit' , 'resetAndFocus' ] ) ;
3137 }
3238
@@ -40,22 +46,20 @@ class CommentForm extends BaseComponent {
4046 switch ( this . state . formMode ) {
4147 case 0 :
4248 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 ,
4551 } ;
4652 break ;
4753 case 1 :
4854 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 ,
5157 } ;
5258 break ;
5359 case 2 :
5460 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 ,
5963 } ;
6064 break ;
6165 default :
@@ -81,13 +85,13 @@ class CommentForm extends BaseComponent {
8185 let ref ;
8286 switch ( this . state . formMode ) {
8387 case 0 :
84- ref = ReactDOM . findDOMNode ( this . refs . horizontalTextNode ) ;
88+ ref = this . horizontalTextRef . current ;
8589 break ;
8690 case 1 :
87- ref = ReactDOM . findDOMNode ( this . refs . stackedTextNode ) ;
91+ ref = this . stackedTextRef . current ;
8892 break ;
8993 case 2 :
90- ref = ReactDOM . findDOMNode ( this . refs . inlineTextNode ) ;
94+ ref = this . inlineTextRef . current ;
9195 break ;
9296 default :
9397 throw new Error ( `Unexpected state.formMode ${ this . state . formMode } ` ) ;
@@ -103,31 +107,31 @@ class CommentForm extends BaseComponent {
103107 < hr />
104108 < form className = "form-horizontal flex flex-col gap-4" onSubmit = { this . handleSubmit } >
105109 < 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" >
107111 { formatMessage ( defaultMessages . inputNameLabel ) }
108112 </ label >
109113 < input
110114 type = "text"
111- id = "horizontalAuthorNode "
115+ id = "horizontalAuthorRef "
112116 placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
113117 className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
114- ref = "horizontalAuthorNode"
118+ ref = { this . horizontalAuthorRef }
115119 value = { this . state . comment . author }
116120 onChange = { this . handleChange }
117121 disabled = { this . props . isSaving }
118122 />
119123 </ div >
120124
121125 < 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" >
123127 { formatMessage ( defaultMessages . inputTextLabel ) }
124128 </ label >
125129 < input
126130 type = "textarea"
127- id = "horizontalTextNode "
131+ id = "horizontalTextRef "
128132 placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
129133 className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
130- ref = "horizontalTextNode"
134+ ref = { this . horizontalTextRef }
131135 value = { this . state . comment . text }
132136 onChange = { this . handleChange }
133137 disabled = { this . props . isSaving }
@@ -158,31 +162,31 @@ class CommentForm extends BaseComponent {
158162 < hr />
159163 < form className = "flex flex-col gap-4" onSubmit = { this . handleSubmit } >
160164 < div className = "flex flex-col gap-0" >
161- < label htmlFor = "stackedAuthorNode " className = "w-full" >
165+ < label htmlFor = "stackedAuthorRef " className = "w-full" >
162166 { formatMessage ( defaultMessages . inputNameLabel ) }
163167 </ label >
164168 < input
165169 type = "text"
166- id = "stackedAuthorNode "
170+ id = "stackedAuthorRef "
167171 placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
168172 className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
169- ref = "stackedAuthorNode"
173+ ref = { this . stackedAuthorRef }
170174 value = { this . state . comment . author }
171175 onChange = { this . handleChange }
172176 disabled = { this . props . isSaving }
173177 />
174178 </ div >
175179
176180 < div className = "flex flex-col gap-0" >
177- < label htmlFor = "stackedTextNode " className = "w-full" >
181+ < label htmlFor = "stackedTextRef " className = "w-full" >
178182 { formatMessage ( defaultMessages . inputTextLabel ) }
179183 </ label >
180184 < input
181185 type = "text"
182- id = "stackedTextNode "
186+ id = "stackedTextRef "
183187 placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
184188 className = "px-3 py-1 leading-4 border border-gray-300 rounded w-full"
185- ref = "stackedTextNode"
189+ ref = { this . stackedTextRef }
186190 value = { this . state . comment . text }
187191 onChange = { this . handleChange }
188192 disabled = { this . props . isSaving }
@@ -213,27 +217,27 @@ class CommentForm extends BaseComponent {
213217 < hr />
214218 < form className = "form-inline flex flex-col lg:flex-row flex-wrap gap-4" onSubmit = { this . handleSubmit } >
215219 < div className = "flex gap-2 items-center" >
216- < label htmlFor = "inlineAuthorNode " > { formatMessage ( defaultMessages . inputNameLabel ) } </ label >
220+ < label htmlFor = "inlineAuthorRef " > { formatMessage ( defaultMessages . inputNameLabel ) } </ label >
217221 < input
218222 type = "text"
219- id = "inlineAuthorNode "
223+ id = "inlineAuthorRef "
220224 placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
221225 className = "px-3 py-1 leading-4 border border-gray-300 rounded"
222- ref = "inlineAuthorNode"
226+ ref = { this . inlineAuthorRef }
223227 value = { this . state . comment . author }
224228 onChange = { this . handleChange }
225229 disabled = { this . props . isSaving }
226230 />
227231 </ div >
228232
229233 < div className = "flex gap-2 items-center" >
230- < label htmlFor = "inlineTextNode " > { formatMessage ( defaultMessages . inputTextLabel ) } </ label >
234+ < label htmlFor = "inlineTextRef " > { formatMessage ( defaultMessages . inputTextLabel ) } </ label >
231235 < input
232236 type = "textarea"
233- id = "inlineTextNode "
237+ id = "inlineTextRef "
234238 placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
235239 className = "px-3 py-1 leading-4 border border-gray-300 rounded"
236- ref = "inlineTextNode"
240+ ref = { this . inlineTextRef }
237241 value = { this . state . comment . text }
238242 onChange = { this . handleChange }
239243 disabled = { this . props . isSaving }
0 commit comments