@@ -436,6 +436,43 @@ describe('Row Chips', () => {
436
436
} ) ) ;
437
437
} ) ;
438
438
439
+ describe ( '_hasInteractiveActions' , ( ) => {
440
+ it ( 'should return true if the chip has a remove icon' , ( ) => {
441
+ testComponent . removable = true ;
442
+ fixture . changeDetectorRef . markForCheck ( ) ;
443
+ fixture . detectChanges ( ) ;
444
+ expect ( chipInstance . _hasInteractiveActions ( ) ) . toBe ( true ) ;
445
+ } ) ;
446
+
447
+ it ( 'should return true if the chip has an edit icon' , ( ) => {
448
+ testComponent . editable = true ;
449
+ testComponent . showEditIcon = true ;
450
+ fixture . changeDetectorRef . markForCheck ( ) ;
451
+ fixture . detectChanges ( ) ;
452
+ expect ( chipInstance . _hasInteractiveActions ( ) ) . toBe ( true ) ;
453
+ } ) ;
454
+
455
+ it ( 'should return true even with a non-interactive trailing icon' , ( ) => {
456
+ testComponent . showTrailingIcon = true ;
457
+ fixture . changeDetectorRef . markForCheck ( ) ;
458
+ fixture . detectChanges ( ) ;
459
+ expect ( chipInstance . _hasInteractiveActions ( ) ) . toBe ( true ) ;
460
+ } ) ;
461
+
462
+ it ( 'should return false if all actions are non-interactive' , ( ) => {
463
+ // Make primary action non-interactive for testing purposes.
464
+ chipInstance . primaryAction . isInteractive = false ;
465
+ testComponent . showTrailingIcon = true ;
466
+ testComponent . removable = false ; // remove icon is interactive
467
+ fixture . changeDetectorRef . markForCheck ( ) ;
468
+ fixture . detectChanges ( ) ;
469
+
470
+ // The trailing icon is not interactive.
471
+ expect ( chipInstance . trailingIcon . isInteractive ) . toBe ( false ) ;
472
+ expect ( chipInstance . _hasInteractiveActions ( ) ) . toBe ( false ) ;
473
+ } ) ;
474
+ } ) ;
475
+
439
476
describe ( 'with edit icon' , ( ) => {
440
477
beforeEach ( async ( ) => {
441
478
testComponent . showEditIcon = true ;
@@ -468,25 +505,10 @@ describe('Row Chips', () => {
468
505
469
506
expect ( primaryGridCell ! . getAttribute ( 'aria-label' ) ) . toMatch ( / c h i p n a m e / i) ;
470
507
471
- const primaryGridCellDescribedBy = primaryGridCell ! . getAttribute ( 'aria-describedby ' ) ;
472
- expect ( primaryGridCellDescribedBy )
473
- . withContext ( 'expected primary grid cell to have a non-empty aria-describedby attribute' )
508
+ const primaryGridCellDescription = primaryGridCell ! . getAttribute ( 'aria-description ' ) ;
509
+ expect ( primaryGridCellDescription )
510
+ . withContext ( 'expected primary grid cell to have a non-empty aria-description attribute' )
474
511
. toBeTruthy ( ) ;
475
-
476
- const primaryGridCellDescriptions = Array . from (
477
- ( fixture . nativeElement as HTMLElement ) . querySelectorAll (
478
- primaryGridCellDescribedBy !
479
- . split ( / \s + / g)
480
- . map ( x => `#${ x } ` )
481
- . join ( ',' ) ,
482
- ) ,
483
- ) ;
484
-
485
- const primaryGridCellDescription = primaryGridCellDescriptions
486
- . map ( x => x . textContent ?. trim ( ) )
487
- . join ( ' ' )
488
- . trim ( ) ;
489
-
490
512
expect ( primaryGridCellDescription ) . toMatch ( / c h i p d e s c r i p t i o n / i) ;
491
513
} ) ;
492
514
} ) ;
@@ -507,10 +529,15 @@ describe('Row Chips', () => {
507
529
<button matChipEdit>edit</button>
508
530
}
509
531
{{name}}
510
- <button matChipRemove>x</button>
532
+ @if (removable) {
533
+ <button matChipRemove>x</button>
534
+ }
511
535
@if (useCustomEditInput) {
512
536
<span class="projected-edit-input" matChipEditInput></span>
513
537
}
538
+ @if (showTrailingIcon) {
539
+ <span matChipTrailingIcon>trailing</span>
540
+ }
514
541
</mat-chip-row>
515
542
<input matInput [matChipInputFor]="chipGrid" #chipInput>
516
543
</div>
@@ -529,6 +556,7 @@ class SingleChip {
529
556
editable : boolean = false ;
530
557
showEditIcon : boolean = false ;
531
558
useCustomEditInput : boolean = true ;
559
+ showTrailingIcon = false ;
532
560
ariaLabel : string | null = null ;
533
561
ariaDescription : string | null = null ;
534
562
0 commit comments