4
4
makeObservable ,
5
5
computed ,
6
6
runInAction ,
7
- IReactionDisposer ,
8
7
action
9
8
} from "mobx" ;
10
9
import classNames from "classnames" ;
@@ -309,30 +308,18 @@ const TextInputWidgetInput = observer(
309
308
password : boolean ;
310
309
iterators : number [ ] ;
311
310
} > {
312
- ref = React . createRef < HTMLInputElement > ( ) ;
313
- cursor : number | null = null ;
311
+ inputElement = React . createRef < HTMLInputElement > ( ) ;
312
+ latestFlowValue : any ;
313
+ inputValue : any ;
314
314
315
315
constructor ( props : any ) {
316
316
super ( props ) ;
317
317
318
318
makeObservable ( this , {
319
- cursor : observable
319
+ inputValue : observable
320
320
} ) ;
321
321
}
322
322
323
- setSelectionRange ( ) {
324
- const input = this . ref . current ;
325
- if ( input ) input . setSelectionRange ( this . cursor , this . cursor ) ;
326
- }
327
-
328
- componentDidMount ( ) {
329
- this . setSelectionRange ( ) ;
330
- }
331
-
332
- componentDidUpdate ( ) {
333
- this . setSelectionRange ( ) ;
334
- }
335
-
336
323
handleKeyDown = ( event : React . KeyboardEvent < HTMLInputElement > ) => {
337
324
if ( event . key === "Enter" ) {
338
325
const flowState = this . props . flowContext . flowState as FlowState ;
@@ -354,13 +341,13 @@ const TextInputWidgetInput = observer(
354
341
onChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
355
342
const { flowContext, textInputWidget, iterators } = this . props ;
356
343
344
+ runInAction ( ( ) => {
345
+ this . inputValue = event . target . value ;
346
+ } ) ;
347
+
357
348
const flowState = flowContext . flowState as FlowState ;
358
349
if ( flowState ) {
359
- runInAction ( ( ) => {
360
- this . cursor = event . target . selectionStart ;
361
- } ) ;
362
-
363
- const value = event . target . value ;
350
+ const value = this . inputValue ;
364
351
365
352
if ( this . props . textInputWidget . data ) {
366
353
assignProperty (
@@ -402,12 +389,26 @@ const TextInputWidgetInput = observer(
402
389
render ( ) {
403
390
const { value, readOnly, placeholder, password } = this . props ;
404
391
392
+ if ( value != this . latestFlowValue ) {
393
+ this . latestFlowValue = value ;
394
+
395
+ setTimeout (
396
+ action ( ( ) => {
397
+ this . inputValue = undefined ;
398
+ } )
399
+ ) ;
400
+ }
401
+
405
402
return (
406
403
< >
407
404
< input
408
- ref = { this . ref }
405
+ ref = { this . inputElement }
409
406
type = { password ? "password" : "text" }
410
- value = { value }
407
+ value = {
408
+ this . inputValue != undefined
409
+ ? this . inputValue
410
+ : value
411
+ }
411
412
placeholder = { placeholder }
412
413
onChange = { this . onChange }
413
414
onBlur = { this . onBlur }
@@ -626,6 +627,10 @@ const NumberInputDashboardWidgetElement = observer(
626
627
disableDefaultTabHandling : boolean ;
627
628
iterators : number [ ] ;
628
629
} > {
630
+ inputElement = React . createRef < HTMLInputElement > ( ) ;
631
+ latestFlowValue : any ;
632
+ inputValue : any ;
633
+
629
634
constructor ( props : any ) {
630
635
super ( props ) ;
631
636
@@ -634,8 +639,6 @@ const NumberInputDashboardWidgetElement = observer(
634
639
} ) ;
635
640
}
636
641
637
- inputElement = React . createRef < HTMLInputElement > ( ) ;
638
-
639
642
componentDidMount ( ) {
640
643
if ( this . props . flowContext . flowState && this . inputElement . current ) {
641
644
this . inputElement . current . focus ( ) ;
@@ -652,10 +655,6 @@ const NumberInputDashboardWidgetElement = observer(
652
655
}
653
656
}
654
657
655
- dispose : IReactionDisposer ;
656
- latestFlowValue : any ;
657
- inputValue : any ;
658
-
659
658
render ( ) {
660
659
const { flowContext, component } = this . props ;
661
660
0 commit comments