@@ -13,11 +13,11 @@ import { IgxComboBaseDirective, IGX_COMBO_COMPONENT } from '../combo/combo.commo
13
13
import { IgxComboModule } from '../combo/combo.component' ;
14
14
import { DisplayDensityToken , IDisplayDensityOptions } from '../core/displayDensity' ;
15
15
import { IgxSelectionAPIService } from '../core/selection' ;
16
- import { CancelableEventArgs , IBaseEventArgs , PlatformUtil } from '../core/utils' ;
16
+ import { CancelableEventArgs , IBaseCancelableBrowserEventArgs , IBaseEventArgs , PlatformUtil } from '../core/utils' ;
17
17
import { IgxButtonModule } from '../directives/button/button.directive' ;
18
18
import { IgxForOfModule } from '../directives/for-of/for_of.directive' ;
19
19
import { IgxRippleModule } from '../directives/ripple/ripple.directive' ;
20
- import { IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive' ;
20
+ import { IgxTextSelectionDirective , IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive' ;
21
21
import { IgxToggleModule } from '../directives/toggle/toggle.directive' ;
22
22
import { IgxDropDownModule } from '../drop-down/public_api' ;
23
23
import { IgxIconModule , IgxIconService } from '../icon/public_api' ;
@@ -76,6 +76,9 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
76
76
@Output ( )
77
77
public selectionChanging = new EventEmitter < ISimpleComboSelectionChangingEventArgs > ( ) ;
78
78
79
+ @ViewChild ( IgxTextSelectionDirective , { static : true } )
80
+ private textSelection : IgxTextSelectionDirective ;
81
+
79
82
/** @hidden @internal */
80
83
public composing = false ;
81
84
@@ -163,14 +166,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
163
166
this . dropdownContainer . nativeElement . focus ( ) ;
164
167
}
165
168
} ) ;
166
- this . dropdown . closed . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => {
167
- this . composing = false ;
168
- } ) ;
169
- this . dropdown . closing . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => {
170
- const selection = this . selectionService . first_item ( this . id ) ;
171
- this . comboInput . value = selection !== undefined && selection !== null ? selection : '' ;
172
- this . _onChangeCallback ( selection ) ;
173
- } ) ;
174
169
175
170
super . ngAfterViewInit ( ) ;
176
171
}
@@ -183,7 +178,13 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
183
178
this . open ( ) ;
184
179
this . dropdown . navigateFirst ( ) ;
185
180
}
181
+ if ( ! this . comboInput . value . trim ( ) ) {
182
+ // handle clearing of input by space
183
+ this . clearSelection ( ) ;
184
+ this . _onChangeCallback ( null ) ;
185
+ }
186
186
super . handleInputChange ( event ) ;
187
+ this . composing = true ;
187
188
}
188
189
189
190
/** @hidden @internal */
@@ -197,6 +198,8 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
197
198
event . preventDefault ( ) ;
198
199
event . stopPropagation ( ) ;
199
200
this . close ( ) ;
201
+ // manually trigger text selection as it will not be triggered during editing
202
+ this . textSelection . trigger ( ) ;
200
203
return ;
201
204
}
202
205
if ( event . key === this . platformUtil . KEYMAP . BACKSPACE
@@ -205,10 +208,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
205
208
this . clearSelection ( ) ;
206
209
}
207
210
super . handleKeyDown ( event ) ;
208
- this . composing = event . key !== this . platformUtil . KEYMAP . ARROW_DOWN
209
- && event . key !== this . platformUtil . KEYMAP . ARROW_LEFT
210
- && event . key !== this . platformUtil . KEYMAP . ARROW_RIGHT
211
- && event . key !== this . platformUtil . KEYMAP . TAB ;
212
211
}
213
212
214
213
/** @hidden @internal */
@@ -250,6 +249,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
250
249
251
250
this . comboInput . value = this . filterValue = this . searchValue = '' ;
252
251
this . dropdown . focusedItem = null ;
252
+ this . composing = false ;
253
253
this . comboInput . focus ( ) ;
254
254
}
255
255
@@ -260,6 +260,24 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
260
260
this . opened . emit ( { owner : this } ) ;
261
261
}
262
262
263
+ /** @hidden @internal */
264
+ public handleClosing ( e : IBaseCancelableBrowserEventArgs ) {
265
+ const args : IBaseCancelableBrowserEventArgs = { owner : this , event : e . event , cancel : e . cancel } ;
266
+ this . closing . emit ( args ) ;
267
+ e . cancel = args . cancel ;
268
+ if ( e . cancel ) {
269
+ return ;
270
+ }
271
+
272
+ this . composing = false ;
273
+ // explicitly update selection so that we don't have to force CD
274
+ this . textSelection . selected = true ;
275
+ const selection = this . selectionService . first_item ( this . id ) ;
276
+ this . _value = selection !== undefined && selection !== null ? selection : '' ;
277
+ this . comboInput . focus ( ) ;
278
+ this . _onChangeCallback ( selection ) ;
279
+ }
280
+
263
281
/** @hidden @internal */
264
282
public focusSearchInput ( opening ?: boolean ) : void {
265
283
if ( opening ) {
@@ -302,7 +320,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
302
320
: [ ] ;
303
321
this . selectionService . select_items ( this . id , argsSelection , true ) ;
304
322
if ( this . _updateInput ) {
305
- this . _value = displayText !== args . displayText
323
+ this . comboInput . value = this . _value = displayText !== args . displayText
306
324
? args . displayText
307
325
: this . createDisplayText ( [ args . newSelection ] , [ args . oldSelection ] ) ;
308
326
}
0 commit comments