@@ -18,10 +18,11 @@ import { IgxSelectionAPIService } from '../core/selection';
18
18
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive' ;
19
19
import { GridBaseAPIService } from './api.service' ;
20
20
import { IgxColumnComponent } from './column.component' ;
21
- import { getNodeSizeViaRange , ROW_COLLAPSE_KEYS , ROW_EXPAND_KEYS , SUPPORTED_KEYS , NAVIGATION_KEYS } from '../core/utils' ;
21
+ import { getNodeSizeViaRange , ROW_COLLAPSE_KEYS , ROW_EXPAND_KEYS , SUPPORTED_KEYS , NAVIGATION_KEYS , isIE } from '../core/utils' ;
22
22
import { State } from '../services/index' ;
23
23
import { IgxGridBaseComponent , IGridEditEventArgs , IGridDataBindable } from './grid-base.component' ;
24
24
import { IgxGridSelectionService , ISelectionNode , IgxGridCRUDService } from '../core/grid-selection' ;
25
+ import { DeprecateProperty } from '../core/deprecateDecorators' ;
25
26
26
27
/**
27
28
* Providing reference to `IgxGridCellComponent`:
@@ -259,41 +260,35 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
259
260
}
260
261
261
262
/**
262
- * Gets whether the cell is in edit mode.
263
+ * @deprecated
264
+ * Use `cell.editMode` as a getter and
265
+ * `cell.setEditMode(true | false)` to start/exit edit mode.
266
+ *
267
+ * Gets/sets whether the cell is in edit mode.
263
268
* ```typescript
264
269
* let isCellInEditMode = this.cell.inEditMode;
265
270
* ```
266
271
* @memberof IgxGridCellComponent
267
272
*/
268
-
269
- // TODO: Deprecate
270
- /**
271
- * @deprecated
272
- */
273
+ @DeprecateProperty ( `'inEditMode' is deprecated\nUse 'editMode' to get the current state and 'setEditMode(boolean)' as a setter` )
273
274
get inEditMode ( ) : boolean {
274
275
return this . editMode ;
275
276
}
276
277
277
278
set inEditMode ( value : boolean ) {
278
- if ( this . row . deleted ) {
279
- return ;
280
- }
281
- if ( this . editable && value ) {
282
- this . gridAPI . submit_value ( ) ;
283
- this . crudService . begin ( this ) ;
284
- } else {
285
- this . gridAPI . escape_editMode ( ) ;
286
- }
287
- this . grid . cdr . markForCheck ( ) ;
279
+ this . setEditMode ( value ) ;
288
280
}
289
281
282
+ /**
283
+ * @hidden
284
+ * @internal
285
+ */
290
286
@Input ( )
291
287
@HostBinding ( 'class.igx-grid__td--pinned-last' )
292
288
lastPinned = false ;
293
289
294
290
/**
295
- * @hidden
296
- * @internal
291
+ * Returns whether the cell is in edit mode.
297
292
*/
298
293
@Input ( )
299
294
@HostBinding ( 'class.igx-grid__td--editing' )
@@ -403,39 +398,12 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
403
398
404
399
return false ;
405
400
}
406
- @ViewChild ( 'defaultCell' , { read : TemplateRef } )
407
- protected defaultCellTemplate : TemplateRef < any > ;
408
-
409
- @ViewChild ( 'inlineEditor' , { read : TemplateRef } )
410
- protected inlineEditorTemplate : TemplateRef < any > ;
411
-
412
- private _highlight : IgxTextHighlightDirective ;
413
-
414
- @ViewChild ( IgxTextHighlightDirective , { read : IgxTextHighlightDirective } )
415
- protected set highlight ( value : IgxTextHighlightDirective ) {
416
- this . _highlight = value ;
417
-
418
- if ( this . _highlight && this . grid . lastSearchInfo . searchText ) {
419
- this . _highlight . highlight ( this . grid . lastSearchInfo . searchText ,
420
- this . grid . lastSearchInfo . caseSensitive ,
421
- this . grid . lastSearchInfo . exactMatch ) ;
422
- this . _highlight . activateIfNecessary ( ) ;
423
- }
424
- }
425
-
426
- protected get highlight ( ) {
427
- return this . _highlight ;
428
- }
429
-
430
- protected get selectionNode ( ) : ISelectionNode {
431
- return { row : this . rowIndex , column : this . visibleColumnIndex } ;
432
- }
433
401
434
402
/**
435
403
* Sets the current edit value while a cell is in edit mode.
436
404
* Only for cell editing mode.
437
405
* ```typescript
438
- * let isLastPinned = this.cell.isLastPinned ;
406
+ * this.cell.editValue = value ;
439
407
* ```
440
408
* @memberof IgxGridCellComponent
441
409
*/
@@ -459,15 +427,53 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
459
427
}
460
428
}
461
429
430
+ /**
431
+ * Returns whether the cell is editable.
432
+ */
462
433
get editable ( ) : boolean {
463
434
return this . column . editable ;
464
435
}
465
436
466
- public isInCompositionMode = false ;
467
-
437
+ /**
438
+ * @hidden
439
+ * @internal
440
+ */
468
441
@HostBinding ( 'class.igx-grid__td--active' )
469
442
public focused = false ;
470
443
444
+ @ViewChild ( 'defaultCell' , { read : TemplateRef } )
445
+ protected defaultCellTemplate : TemplateRef < any > ;
446
+
447
+ @ViewChild ( 'inlineEditor' , { read : TemplateRef } )
448
+ protected inlineEditorTemplate : TemplateRef < any > ;
449
+
450
+ @ViewChild ( IgxTextHighlightDirective , { read : IgxTextHighlightDirective } )
451
+ protected set highlight ( value : IgxTextHighlightDirective ) {
452
+ this . _highlight = value ;
453
+
454
+ if ( this . _highlight && this . grid . lastSearchInfo . searchText ) {
455
+ this . _highlight . highlight ( this . grid . lastSearchInfo . searchText ,
456
+ this . grid . lastSearchInfo . caseSensitive ,
457
+ this . grid . lastSearchInfo . exactMatch ) ;
458
+ this . _highlight . activateIfNecessary ( ) ;
459
+ }
460
+ }
461
+
462
+ protected get highlight ( ) {
463
+ return this . _highlight ;
464
+ }
465
+
466
+ protected get selectionNode ( ) : ISelectionNode {
467
+ return { row : this . rowIndex , column : this . visibleColumnIndex } ;
468
+ }
469
+
470
+ protected isInCompositionMode = false ;
471
+ protected compositionStartHandler ;
472
+ protected compositionEndHandler ;
473
+ protected focusHandlerIE ;
474
+ protected focusOut ;
475
+ private _highlight : IgxTextHighlightDirective ;
476
+
471
477
472
478
constructor (
473
479
protected selectionService : IgxGridSelectionService ,
@@ -479,22 +485,53 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
479
485
protected zone : NgZone ) { }
480
486
481
487
488
+ /**
489
+ * @hidden
490
+ * @internal
491
+ */
482
492
ngOnInit ( ) {
483
493
this . zone . runOutsideAngular ( ( ) => {
484
494
this . nativeElement . addEventListener ( 'pointerdown' , this . pointerdown ) ;
485
495
this . nativeElement . addEventListener ( 'pointerenter' , this . pointerenter ) ;
486
496
this . nativeElement . addEventListener ( 'pointerup' , this . pointerup ) ;
497
+
498
+ // IE 11 workarounds
499
+ if ( isIE ( ) ) {
500
+ // Hitting Enter with IME submits and exits from edit mode instead of first closing the IME dialog
501
+ this . compositionStartHandler = this . nativeElement
502
+ . addEventListener ( 'compositionstart' , ( ) => this . isInCompositionMode = true ) ;
503
+ this . compositionEndHandler = this . nativeElement . addEventListener ( 'compositionend' , ( ) => this . isInCompositionMode = false ) ;
504
+
505
+ // https://stackoverflow.com/q/51404782
506
+ this . focusHandlerIE = this . nativeElement . addEventListener ( 'focusin' , ( e : FocusEvent ) => this . onFocus ( e ) ) ;
507
+ this . focusOut = this . nativeElement . addEventListener ( 'focusout' , ( ) => this . onBlur ( ) ) ;
508
+ }
487
509
} ) ;
488
510
}
489
511
512
+ /**
513
+ * @hidden
514
+ * @internal
515
+ */
490
516
ngOnDestroy ( ) {
491
517
this . zone . runOutsideAngular ( ( ) => {
492
518
this . nativeElement . removeEventListener ( 'pointerdown' , this . pointerdown ) ;
493
519
this . nativeElement . removeEventListener ( 'pointerenter' , this . pointerenter ) ;
494
520
this . nativeElement . removeEventListener ( 'pointerup' , this . pointerup ) ;
521
+
522
+ if ( isIE ( ) ) {
523
+ this . nativeElement . removeEventListener ( 'compositionstart' , this . compositionStartHandler ) ;
524
+ this . nativeElement . removeEventListener ( 'compositionend' , this . compositionEndHandler ) ;
525
+ this . nativeElement . removeEventListener ( 'focusin' , this . focusHandlerIE ) ;
526
+ this . nativeElement . removeEventListener ( 'focusout' , this . focusOut ) ;
527
+ }
495
528
} ) ;
496
529
}
497
530
531
+ /**
532
+ * @hidden
533
+ * @internal
534
+ */
498
535
_updateCRUDStatus ( ) {
499
536
if ( this . editable && this . crudService . inEditMode && ! this . row . deleted ) {
500
537
this . gridAPI . update_cell ( this . crudService . cell , this . crudService . cell . editValue ) ;
@@ -533,7 +570,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
533
570
}
534
571
535
572
/**
536
- *@hidden
573
+ * @hidden
574
+ * @internal
537
575
*/
538
576
public ngOnChanges ( changes : SimpleChanges ) : void {
539
577
if ( changes . value && ! changes . value . firstChange ) {
@@ -545,6 +583,26 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
545
583
}
546
584
}
547
585
586
+ /**
587
+ * Starts/ends edit mode for the cell.
588
+ *
589
+ * ```typescript
590
+ * cell.setEditMode(true);
591
+ * ```
592
+ */
593
+ setEditMode ( value : boolean ) : void {
594
+ if ( this . row . deleted ) {
595
+ return ;
596
+ }
597
+ if ( this . editable && value ) {
598
+ this . gridAPI . submit_value ( ) ;
599
+ this . crudService . begin ( this ) ;
600
+ } else {
601
+ this . gridAPI . escape_editMode ( ) ;
602
+ }
603
+ this . grid . cdr . markForCheck ( ) ;
604
+ }
605
+
548
606
/**
549
607
* Sets new value to the cell.
550
608
* ```typescript
@@ -663,7 +721,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
663
721
this . row . focused = false ;
664
722
}
665
723
666
- protected handleAlt ( key : string ) {
724
+ protected handleAlt ( key : string , event : KeyboardEvent ) {
667
725
if ( this . row . nativeElement . tagName . toLowerCase ( ) === 'igx-tree-grid-row' && this . isToggleKey ( key ) ) {
668
726
const collapse = ( this . row as any ) . expanded && ROW_COLLAPSE_KEYS . has ( key ) ;
669
727
const expand = ! ( this . row as any ) . expanded && ROW_EXPAND_KEYS . has ( key ) ;
@@ -719,7 +777,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
719
777
}
720
778
721
779
if ( event . altKey ) {
722
- this . handleAlt ( key ) ;
780
+ this . handleAlt ( key , event ) ;
723
781
return ;
724
782
}
725
783
@@ -839,6 +897,10 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
839
897
* @internal
840
898
*/
841
899
public onKeydownExitEditMode ( ) {
900
+ if ( this . isInCompositionMode ) {
901
+ return ;
902
+ }
903
+
842
904
if ( this . editMode ) {
843
905
const v = this . crudService . cell ;
844
906
const args = {
0 commit comments