Skip to content

Commit c29ff84

Browse files
committed
fix(material/chips): static chips should disable ripple
1 parent 57adabc commit c29ff84

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/material/chips/chip-row.spec.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,39 @@ describe('Row Chips', () => {
436436
}));
437437
});
438438

439+
describe('_hasInteractiveActions', () => {
440+
it('should return true if the chip has a remove icon', () => {
441+
testComponent.removable = true;
442+
fixture.detectChanges();
443+
expect(chipInstance._hasInteractiveActions()).toBe(true);
444+
});
445+
446+
it('should return true if the chip has an edit icon', () => {
447+
testComponent.editable = true;
448+
testComponent.showEditIcon = true;
449+
fixture.detectChanges();
450+
expect(chipInstance._hasInteractiveActions()).toBe(true);
451+
});
452+
453+
it('should return true even with a non-interactive trailing icon', () => {
454+
testComponent.showTrailingIcon = true;
455+
fixture.detectChanges();
456+
expect(chipInstance._hasInteractiveActions()).toBe(true);
457+
});
458+
459+
it('should return false if all actions are non-interactive', () => {
460+
// Make primary action non-interactive for testing purposes.
461+
chipInstance.primaryAction.isInteractive = false;
462+
testComponent.showTrailingIcon = true;
463+
testComponent.removable = false; // remove icon is interactive
464+
fixture.detectChanges();
465+
466+
// The trailing icon is not interactive.
467+
expect(chipInstance.trailingIcon.isInteractive).toBe(false);
468+
expect(chipInstance._hasInteractiveActions()).toBe(false);
469+
});
470+
});
471+
439472
describe('with edit icon', () => {
440473
beforeEach(async () => {
441474
testComponent.showEditIcon = true;
@@ -507,10 +540,15 @@ describe('Row Chips', () => {
507540
<button matChipEdit>edit</button>
508541
}
509542
{{name}}
510-
<button matChipRemove>x</button>
543+
@if (removable) {
544+
<button matChipRemove>x</button>
545+
}
511546
@if (useCustomEditInput) {
512547
<span class="projected-edit-input" matChipEditInput></span>
513548
}
549+
@if (showTrailingIcon) {
550+
<span matChipTrailingIcon>trailing</span>
551+
}
514552
</mat-chip-row>
515553
<input matInput [matChipInputFor]="chipGrid" #chipInput>
516554
</div>
@@ -529,6 +567,7 @@ class SingleChip {
529567
editable: boolean = false;
530568
showEditIcon: boolean = false;
531569
useCustomEditInput: boolean = true;
570+
showTrailingIcon = false;
532571
ariaLabel: string | null = null;
533572
ariaDescription: string | null = null;
534573

src/material/chips/chip.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ describe('MatChip', () => {
117117
expect(primaryAction.hasAttribute('tabindex')).toBe(false);
118118
});
119119

120+
it('should disable the ripple if there are no interactive actions', () => {
121+
expect(chipInstance._isRippleDisabled()).toBe(false);
122+
123+
// Make primary action non-interactive for testing purposes.
124+
chipInstance.primaryAction.isInteractive = false;
125+
fixture.changeDetectorRef.markForCheck();
126+
fixture.detectChanges();
127+
128+
expect(chipInstance._hasInteractiveActions()).toBe(false);
129+
expect(chipInstance._isRippleDisabled()).toBe(true);
130+
});
131+
120132
it('should return the chip text if value is undefined', () => {
121133
expect(chipInstance.value.trim()).toBe(fixture.componentInstance.name);
122134
});

src/material/chips/chip.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
327327
this.disableRipple ||
328328
this._animationsDisabled ||
329329
this._isBasicChip ||
330+
!this._hasInteractiveActions() ||
330331
!!this._globalRippleOptions?.disabled
331332
);
332333
}
@@ -396,6 +397,11 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
396397
// Empty here, but is overwritten in child classes.
397398
}
398399

400+
/** Returns whether the chip has any interactive actions. */
401+
_hasInteractiveActions(): boolean {
402+
return this._getActions().some(a => a.isInteractive);
403+
}
404+
399405
/** Handles interactions with the edit action of the chip. */
400406
_edit(event: Event) {
401407
// Empty here, but is overwritten in child classes.

0 commit comments

Comments
 (0)