1
1
import WebComponent from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/WebComponent" ;
2
2
import Bootstrap from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/Bootstrap" ;
3
+ import { isIE } from "@ui5/webcomponents-core/dist/sap/ui/Device" ;
3
4
import ValueState from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/types/ValueState" ;
4
5
import ShadowDOM from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/compatibility/ShadowDOM" ;
5
6
import {
@@ -285,17 +286,14 @@ class Input extends WebComponent {
285
286
// Indicates if there is selected suggestionItem.
286
287
this . hasSuggestionItemSelected = false ;
287
288
288
- // Indicates if there is focused suggestionItem.
289
- // Used to ignore the Input "focusedOut" and thus preventing firing "change" event.
290
- this . hasSuggestionItemFocused = false ;
291
-
292
- this . previousValue = undefined ;
293
-
294
289
// Represents the value before user moves selection between the suggestion items.
295
290
// Used to register and fire "input" event upon [SPACE] or [ENTER].
296
291
// Note: the property "value" is updated upon selection move and can`t be used.
297
292
this . valueBeforeItemSelection = "" ;
298
293
294
+ // tracks the value between focus in and focus out to detect that change event should be fired.
295
+ this . previousValue = undefined ;
296
+
299
297
// Indicates, if the component is rendering for first time.
300
298
this . firstRendering = true ;
301
299
@@ -307,11 +305,13 @@ class Input extends WebComponent {
307
305
308
306
// all user interactions
309
307
this . ACTION_ENTER = "enter" ;
310
- this . ACTION_FOCUSOUT = "focusOut" ;
311
308
this . ACTION_USER_INPUT = "input" ;
312
309
313
310
this . _input = {
314
311
onInput : this . _onInput . bind ( this ) ,
312
+ change : event => {
313
+ this . fireEvent ( this . EVENT_CHANGE ) ;
314
+ } ,
315
315
} ;
316
316
317
317
this . _whenShadowRootReady ( ) . then ( this . attachFocusHandlers . bind ( this ) ) ;
@@ -327,7 +327,6 @@ class Input extends WebComponent {
327
327
if ( ! this . firstRendering && this . Suggestions ) {
328
328
this . Suggestions . toggle ( this . shouldOpenSuggestions ( ) ) ;
329
329
}
330
- this . checkFocusOut ( ) ;
331
330
this . firstRendering = false ;
332
331
}
333
332
@@ -392,13 +391,13 @@ class Input extends WebComponent {
392
391
}
393
392
394
393
onfocusin ( ) {
395
- this . previousValue = this . value ;
396
- this . hasSuggestionItemFocused = false ;
397
394
this . _focused = true ; // invalidating property
395
+ this . previousValue = this . value ;
398
396
}
399
397
400
398
onfocusout ( ) {
401
399
this . _focused = false ; // invalidating property
400
+ this . previousValue = "" ;
402
401
}
403
402
404
403
_onInput ( event ) {
@@ -454,6 +453,7 @@ class Input extends WebComponent {
454
453
this . value = itemText ;
455
454
this . valueBeforeItemSelection = itemText ;
456
455
this . fireEvent ( this . EVENT_INPUT ) ;
456
+ this . fireEvent ( this . EVENT_CHANGE ) ;
457
457
}
458
458
}
459
459
@@ -469,35 +469,27 @@ class Input extends WebComponent {
469
469
470
470
const inputValue = this . getInputValue ( ) ;
471
471
const isSubmit = action === this . ACTION_ENTER ;
472
- const isFocusOut = action === this . ACTION_FOCUSOUT ;
473
472
const isUserInput = action === this . ACTION_USER_INPUT ;
474
473
475
474
this . value = inputValue ;
476
475
477
- const valueChanged = ( this . previousValue !== undefined ) && ( this . previousValue !== this . value ) ;
478
-
479
476
if ( isUserInput ) { // input
480
477
this . fireEvent ( this . EVENT_INPUT ) ;
481
478
return ;
482
479
}
483
480
484
- if ( ( isSubmit || isFocusOut ) && valueChanged ) { // change
485
- this . previousValue = this . value ;
486
- this . fireEvent ( this . EVENT_CHANGE ) ;
487
- }
488
-
489
481
if ( isSubmit ) { // submit
490
482
this . fireEvent ( this . EVENT_SUBMIT ) ;
491
483
}
492
- }
493
484
494
- checkFocusOut ( ) {
495
- if ( ! this . _focused && ! this . hasSuggestionItemFocused ) {
496
- this . fireEventByAction ( this . ACTION_FOCUSOUT ) ;
497
- this . previousValue = "" ;
485
+ // In IE, pressing the ENTER does not fire change
486
+ const valueChanged = ( this . previousValue !== undefined ) && ( this . previousValue !== this . value ) ;
487
+ if ( isIE ( ) && isSubmit && valueChanged ) {
488
+ this . fireEvent ( this . EVENT_CHANGE ) ;
498
489
}
499
490
}
500
491
492
+
501
493
getInputValue ( ) {
502
494
const inputDOM = this . getDomRef ( ) ;
503
495
if ( inputDOM ) {
@@ -519,9 +511,7 @@ class Input extends WebComponent {
519
511
}
520
512
521
513
/* Suggestions interface */
522
- onItemFocused ( ) {
523
- this . hasSuggestionItemFocused = true ;
524
- }
514
+ onItemFocused ( ) { }
525
515
526
516
onItemSelected ( item , keyboardUsed ) {
527
517
this . selectSuggestion ( item , keyboardUsed ) ;
0 commit comments