@@ -77,7 +77,6 @@ class TextInput extends Component<TextInputProps, TextInputState> {
7777 super ( props )
7878 this . state = {
7979 hasFocus : false ,
80- beforeElementHasWidth : undefined ,
8180 afterElementHasWidth : undefined
8281 }
8382 this . _defaultId = props . deterministicId ! ( )
@@ -87,7 +86,6 @@ class TextInput extends Component<TextInputProps, TextInputState> {
8786 ref : Element | null = null
8887
8988 private _input : HTMLInputElement | null = null
90- private _beforeElement : HTMLSpanElement | null = null
9189 private _afterElement : HTMLSpanElement | null = null
9290
9391 private readonly _defaultId : string
@@ -112,13 +110,10 @@ class TextInput extends Component<TextInputProps, TextInputState> {
112110 'focus' ,
113111 this . handleFocus
114112 )
115-
116113 this . setState ( {
117- beforeElementHasWidth : this . getElementHasWidth ( this . _beforeElement ) ,
118114 afterElementHasWidth : this . getElementHasWidth ( this . _afterElement )
119115 } )
120116 }
121-
122117 this . props . makeStyles ?.( this . makeStyleProps ( ) )
123118 }
124119
@@ -129,11 +124,6 @@ class TextInput extends Component<TextInputProps, TextInputState> {
129124 }
130125
131126 componentDidUpdate ( prevProps : TextInputProps ) {
132- if ( prevProps . renderBeforeInput !== this . props . renderBeforeInput ) {
133- this . setState ( {
134- beforeElementHasWidth : this . getElementHasWidth ( this . _beforeElement )
135- } )
136- }
137127 if ( prevProps . renderAfterInput !== this . props . renderAfterInput ) {
138128 this . setState ( {
139129 afterElementHasWidth : this . getElementHasWidth ( this . _afterElement )
@@ -154,13 +144,13 @@ class TextInput extends Component<TextInputProps, TextInputState> {
154144
155145 makeStyleProps = ( ) : TextInputStyleProps => {
156146 const { interaction } = this
157- const { hasFocus, beforeElementHasWidth , afterElementHasWidth } = this . state
147+ const { hasFocus, afterElementHasWidth } = this . state
158148 return {
159149 disabled : interaction === 'disabled' ,
160150 invalid : this . invalid ,
161151 focused : hasFocus ,
162- beforeElementHasWidth ,
163- afterElementHasWidth
152+ afterElementHasWidth : afterElementHasWidth ,
153+ beforeElementExists : this . props . renderBeforeInput != undefined
164154 }
165155 }
166156
@@ -282,7 +272,7 @@ class TextInput extends Component<TextInputProps, TextInputState> {
282272 )
283273 }
284274
285- getElementHasWidth ( element : HTMLSpanElement | null ) {
275+ getElementHasWidth ( element : Element | null ) {
286276 if ( ! element ) {
287277 return undefined
288278 }
@@ -360,39 +350,24 @@ class TextInput extends Component<TextInputProps, TextInputState> {
360350 >
361351 < span css = { styles ?. facade } >
362352 { renderBeforeOrAfter ? (
363- < div >
364- < span css = { styles ?. layout } >
365- { beforeElement && (
353+ < span css = { styles ?. layout } >
354+ { beforeElement }
355+ { /* The input and content after input should not wrap,
356+ so they're in their own flex container */ }
357+ < span css = { styles ?. inputLayout } >
358+ { this . renderInput ( ) }
359+ { afterElement && (
366360 < span
367- css = { styles ?. beforeElement }
361+ css = { styles ?. afterElement }
368362 ref = { ( e ) => {
369- this . _beforeElement = e
363+ this . _afterElement = e
370364 } }
371365 >
372- { beforeElement }
366+ { afterElement }
373367 </ span >
374368 ) }
375- < span css = { styles ?. innerWrapper } >
376- { /*
377- The input and content after input should not wrap,
378- so they're in their own flex container
379- */ }
380- < span css = { styles ?. inputLayout } >
381- < span css = { styles ?. innerWrapper } > { this . renderInput ( ) } </ span >
382- { afterElement && (
383- < span
384- css = { styles ?. afterElement }
385- ref = { ( e ) => {
386- this . _afterElement = e
387- } }
388- >
389- { afterElement }
390- </ span >
391- ) }
392- </ span >
393- </ span >
394369 </ span >
395- </ div >
370+ </ span >
396371 ) : (
397372 /* If no prepended or appended content, don't render Flex layout */
398373 this . renderInput ( )
0 commit comments