@@ -174,5 +174,39 @@ describe('ReactInputSelection', () => {
174
174
175
175
document . body . removeChild ( input ) ;
176
176
} ) ;
177
+
178
+ it ( 'gets and restores selection for inputs in an iframe that get remounted' , ( ) => {
179
+ var iframe = document . createElement ( 'iframe' ) ;
180
+ iframe . setAttribute ( 'tabIndex' , 0 ) ;
181
+ document . body . appendChild ( iframe ) ;
182
+ iframe . focus ( ) ;
183
+ var iframeDoc = iframe . contentDocument ;
184
+ var input = document . createElement ( 'input' ) ;
185
+ input . value = textValue ;
186
+ iframeDoc . body . appendChild ( input ) ;
187
+ // Focus iframe first to get around jsdom limitations
188
+ iframe . focus ( ) ;
189
+ input . focus ( ) ;
190
+ input . selectionStart = 1 ;
191
+ input . selectionEnd = 10 ;
192
+ var selectionInfo = ReactInputSelection . getSelectionInformation ( ) ;
193
+ expect ( selectionInfo . focusedElement ) . toBe ( input ) ;
194
+ expect ( selectionInfo . activeElements [ 0 ] . selectionRange ) . toEqual ( { start : 1 , end : 10 } ) ;
195
+ expect ( document . activeElement ) . toBe ( iframe ) ;
196
+ expect ( iframeDoc . activeElement ) . toBe ( input ) ;
197
+
198
+ input . setSelectionRange ( 0 , 0 ) ;
199
+ iframeDoc . body . removeChild ( input ) ;
200
+ expect ( iframeDoc . activeElement ) . not . toBe ( input ) ;
201
+ expect ( input . selectionStart ) . not . toBe ( 1 ) ;
202
+ expect ( input . selectionEnd ) . not . toBe ( 10 ) ;
203
+ iframeDoc . body . appendChild ( input ) ;
204
+ ReactInputSelection . restoreSelection ( selectionInfo ) ;
205
+ expect ( iframeDoc . activeElement ) . toBe ( input ) ;
206
+ expect ( input . selectionStart ) . toBe ( 1 ) ;
207
+ expect ( input . selectionEnd ) . toBe ( 10 ) ;
208
+
209
+ document . body . removeChild ( iframe ) ;
210
+ } ) ;
177
211
} ) ;
178
212
} ) ;
0 commit comments