diff --git a/src/material/chips/BUILD.bazel b/src/material/chips/BUILD.bazel index 0146ffcfaa3e..88dce798fd88 100644 --- a/src/material/chips/BUILD.bazel +++ b/src/material/chips/BUILD.bazel @@ -127,6 +127,7 @@ ng_project( "//src/cdk/testing/private", "//src/material/core", "//src/material/form-field", + "//src/material/icon", "//src/material/input", ], ) diff --git a/src/material/chips/chip.scss b/src/material/chips/chip.scss index b5a316cb75dc..30d693529218 100644 --- a/src/material/chips/chip.scss +++ b/src/material/chips/chip.scss @@ -446,6 +446,11 @@ $fallbacks: m3-chip.get-tokens(); font-size: token-utils.slot(chip-with-icon-icon-size, $fallbacks); } + // `mat-icon` clips its content which, combined with the avatar shape, cuts off its corners. + .mat-mdc-standard-chip &.mat-icon { + overflow: visible; + } + .mdc-evolution-chip--selected & { opacity: 0; } diff --git a/src/material/chips/chip.spec.ts b/src/material/chips/chip.spec.ts index b08260c16d1e..bae01fb1a832 100644 --- a/src/material/chips/chip.spec.ts +++ b/src/material/chips/chip.spec.ts @@ -2,6 +2,7 @@ import {provideFakeDirectionality} from '@angular/cdk/testing/private'; import {Component, DebugElement, ViewChild, ChangeDetectionStrategy} from '@angular/core'; import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing'; import {By} from '@angular/platform-browser'; +import {MatIconModule} from '../icon'; import {MatChip, MatChipEvent, MatChipSet, MatChipsModule} from './index'; describe('MatChip', () => { @@ -141,6 +142,14 @@ describe('MatChip', () => { expect(chipInstance.value).toBeNull(); }); }); + + it('should not clip the corners of icon avatars', () => { + fixture = TestBed.createComponent(ChipWithIconAvatar); + fixture.detectChanges(); + + const avatar = fixture.nativeElement.querySelector('.mat-mdc-chip-avatar'); + expect(getComputedStyle(avatar).overflow).toBe('visible'); + }); }); @Component({ @@ -196,3 +205,14 @@ class BasicChipWithStaticTabindex {} class BasicChipWithBoundTabindex { tabindex = 12; } + +@Component({ + template: ` + + eventEvent + + `, + imports: [MatChipsModule, MatIconModule], + changeDetection: ChangeDetectionStrategy.Eager, +}) +class ChipWithIconAvatar {} diff --git a/src/material/chips/chips.md b/src/material/chips/chips.md index c0c0851f70a8..4ac45faeebf7 100644 --- a/src/material/chips/chips.md +++ b/src/material/chips/chips.md @@ -78,10 +78,19 @@ You can add icons to chips to identify entities (like individuals) and provide a You can add two additional icons to an individual chip. A chip has two slots to display icons using content projection. All variants of chips support adding icons including ``, ``, and ``. -A chip has a front slot for adding an avatar image. To add an avatar, nest an element with `matChipAvatar` attribute inside of ``. +A chip has a front slot for adding an avatar image or a leading icon. To use it, nest an element with the `matChipAvatar` attribute inside of the chip. Content without this attribute is rendered as part of the chip's text. +Icons can be added to the front slot the same way. + +```html + + event + Meeting + +``` + You can add an additional icon to the back slot by nesting an element with either the `matChipTrailingIcon` or `matChipRemove` attribute. #### Remove Button