Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goldens/material/chips/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
_handlePrimaryActionInteraction(): void;
// (undocumented)
_hasFocus(): boolean;
_hasInteractiveActions(): boolean;
_hasTrailingIcon(): boolean;
highlighted: boolean;
id: string;
Expand Down
45 changes: 44 additions & 1 deletion src/material/chips/chip-row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,43 @@ describe('Row Chips', () => {
}));
});

describe('_hasInteractiveActions', () => {
it('should return true if the chip has a remove icon', () => {
testComponent.removable = true;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(chipInstance._hasInteractiveActions()).toBe(true);
});

it('should return true if the chip has an edit icon', () => {
testComponent.editable = true;
testComponent.showEditIcon = true;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(chipInstance._hasInteractiveActions()).toBe(true);
});

it('should return true even with a non-interactive trailing icon', () => {
testComponent.showTrailingIcon = true;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(chipInstance._hasInteractiveActions()).toBe(true);
});

it('should return false if all actions are non-interactive', () => {
// Make primary action non-interactive for testing purposes.
chipInstance.primaryAction.isInteractive = false;
testComponent.showTrailingIcon = true;
testComponent.removable = false; // remove icon is interactive
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

// The trailing icon is not interactive.
expect(chipInstance.trailingIcon.isInteractive).toBe(false);
expect(chipInstance._hasInteractiveActions()).toBe(false);
});
});

describe('with edit icon', () => {
beforeEach(async () => {
testComponent.showEditIcon = true;
Expand Down Expand Up @@ -507,10 +544,15 @@ describe('Row Chips', () => {
<button matChipEdit>edit</button>
}
{{name}}
<button matChipRemove>x</button>
@if (removable) {
<button matChipRemove>x</button>
}
@if (useCustomEditInput) {
<span class="projected-edit-input" matChipEditInput></span>
}
@if (showTrailingIcon) {
<span matChipTrailingIcon>trailing</span>
}
</mat-chip-row>
<input matInput [matChipInputFor]="chipGrid" #chipInput>
</div>
Expand All @@ -529,6 +571,7 @@ class SingleChip {
editable: boolean = false;
showEditIcon: boolean = false;
useCustomEditInput: boolean = true;
showTrailingIcon = false;
ariaLabel: string | null = null;
ariaDescription: string | null = null;

Expand Down
12 changes: 12 additions & 0 deletions src/material/chips/chip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ describe('MatChip', () => {
expect(primaryAction.hasAttribute('tabindex')).toBe(false);
});

it('should disable the ripple if there are no interactive actions', () => {
// expect(chipInstance._isRippleDisabled()).toBe(false); TODO(andreyd)

// Make primary action non-interactive for testing purposes.
chipInstance.primaryAction.isInteractive = false;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

expect(chipInstance._hasInteractiveActions()).toBe(false);
expect(chipInstance._isRippleDisabled()).toBe(true);
});

it('should return the chip text if value is undefined', () => {
expect(chipInstance.value.trim()).toBe(fixture.componentInstance.name);
});
Expand Down
6 changes: 6 additions & 0 deletions src/material/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
this.disableRipple ||
this._animationsDisabled ||
this._isBasicChip ||
!this._hasInteractiveActions() ||
!!this._globalRippleOptions?.disabled
);
}
Expand Down Expand Up @@ -396,6 +397,11 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
// Empty here, but is overwritten in child classes.
}

/** Returns whether the chip has any interactive actions. */
_hasInteractiveActions(): boolean {
return this._getActions().some(a => a.isInteractive);
}

/** Handles interactions with the edit action of the chip. */
_edit(event: Event) {
// Empty here, but is overwritten in child classes.
Expand Down
Loading