Skip to content

Commit 8da079d

Browse files
authored
fix(material/chips): remove extra span for aria-description (#31609)
1 parent 37648cf commit 8da079d

File tree

6 files changed

+10
-48
lines changed

6 files changed

+10
-48
lines changed

goldens/material/chips/index.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
5959
protected _allTrailingIcons: QueryList<MatChipTrailingIcon>;
6060
_animationsDisabled: boolean;
6161
ariaDescription: string | null;
62-
_ariaDescriptionId: string;
6362
ariaLabel: string | null;
6463
protected basicChipAttrName: string;
6564
// (undocumented)

src/material/chips/chip-option.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<button
55
matChipAction
66
[_allowFocusWhenDisabled]="true"
7-
[attr.aria-selected]="ariaSelected"
7+
[attr.aria-description]="ariaDescription"
88
[attr.aria-label]="ariaLabel"
9-
[attr.aria-describedby]="_ariaDescriptionId"
9+
[attr.aria-selected]="ariaSelected"
1010
role="option">
1111
@if (_hasLeadingGraphic()) {
1212
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic">
@@ -35,5 +35,3 @@
3535
<ng-content select="mat-chip-trailing-icon,[matChipRemove],[matChipTrailingIcon]"></ng-content>
3636
</span>
3737
}
38-
39-
<span class="cdk-visually-hidden" [id]="_ariaDescriptionId">{{ariaDescription}}</span>

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,25 +337,10 @@ describe('Option Chips', () => {
337337

338338
expect(optionElement.getAttribute('aria-label')).toMatch(/option name/i);
339339

340-
const optionElementDescribedBy = optionElement!.getAttribute('aria-describedby');
341-
expect(optionElementDescribedBy)
342-
.withContext('expected primary grid cell to have a non-empty aria-describedby attribute')
340+
const optionElementDescription = optionElement!.getAttribute('aria-description');
341+
expect(optionElementDescription)
342+
.withContext('expected primary grid cell to have a non-empty aria-description attribute')
343343
.toBeTruthy();
344-
345-
const optionElementDescriptions = Array.from(
346-
(fixture.nativeElement as HTMLElement).querySelectorAll(
347-
optionElementDescribedBy!
348-
.split(/\s+/g)
349-
.map(x => `#${x}`)
350-
.join(','),
351-
),
352-
);
353-
354-
const optionElementDescription = optionElementDescriptions
355-
.map(x => x.textContent?.trim())
356-
.join(' ')
357-
.trim();
358-
359344
expect(optionElementDescription).toMatch(/option description/i);
360345
});
361346

src/material/chips/chip-row.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<span class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary" role="gridcell"
1111
matChipAction
1212
[disabled]="disabled"
13-
[attr.aria-label]="ariaLabel"
14-
[attr.aria-describedby]="_ariaDescriptionId">
13+
[attr.aria-description]="ariaDescription"
14+
[attr.aria-label]="ariaLabel">
1515
@if (leadingIcon) {
1616
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic">
1717
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
@@ -40,5 +40,3 @@
4040
<ng-content select="mat-chip-trailing-icon,[matChipRemove],[matChipTrailingIcon]"></ng-content>
4141
</span>
4242
}
43-
44-
<span class="cdk-visually-hidden" [id]="_ariaDescriptionId">{{ariaDescription}}</span>

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -505,25 +505,10 @@ describe('Row Chips', () => {
505505

506506
expect(primaryGridCell!.getAttribute('aria-label')).toMatch(/chip name/i);
507507

508-
const primaryGridCellDescribedBy = primaryGridCell!.getAttribute('aria-describedby');
509-
expect(primaryGridCellDescribedBy)
510-
.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')
511511
.toBeTruthy();
512-
513-
const primaryGridCellDescriptions = Array.from(
514-
(fixture.nativeElement as HTMLElement).querySelectorAll(
515-
primaryGridCellDescribedBy!
516-
.split(/\s+/g)
517-
.map(x => `#${x}`)
518-
.join(','),
519-
),
520-
);
521-
522-
const primaryGridCellDescription = primaryGridCellDescriptions
523-
.map(x => x.textContent?.trim())
524-
.join(' ')
525-
.trim();
526-
527512
expect(primaryGridCellDescription).toMatch(/chip description/i);
528513
});
529514
});

src/material/chips/chip.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck
166166
/** ARIA description for the content of the chip. */
167167
@Input('aria-description') ariaDescription: string | null = null;
168168

169-
/** Id of a span that contains this chip's aria description. */
170-
_ariaDescriptionId = `${this.id}-aria-description`;
171-
172169
/** Whether the chip list is disabled. */
173170
_chipListDisabled: boolean = false;
174171

0 commit comments

Comments
 (0)