Skip to content

fix(material/chips): remove button role from editable chips #27317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2023
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
27 changes: 12 additions & 15 deletions src/material/chips/chip-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@
</ng-container>


<span class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary" role="gridcell">
<span
<span class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary" role="gridcell"
matChipAction
[attr.role]="editable ? 'button' : null"
[tabIndex]="tabIndex"
[disabled]="disabled"
[attr.aria-label]="ariaLabel"
[attr.aria-describedby]="_ariaDescriptionId">
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic" *ngIf="leadingIcon">
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
</span>
<span class="mdc-evolution-chip__text-label mat-mdc-chip-action-label" [ngSwitch]="_isEditing">
<ng-container *ngSwitchCase="false"><ng-content></ng-content></ng-container>
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic" *ngIf="leadingIcon">
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
</span>
<span class="mdc-evolution-chip__text-label mat-mdc-chip-action-label" [ngSwitch]="_isEditing">
<ng-container *ngSwitchCase="false"><ng-content></ng-content></ng-container>

<ng-container *ngSwitchCase="true">
<ng-content *ngIf="contentEditInput; else defaultMatChipEditInput"
select="[matChipEditInput]"></ng-content>
<ng-template #defaultMatChipEditInput><span matChipEditInput></span></ng-template>
</ng-container>
<ng-container *ngSwitchCase="true">
<ng-content *ngIf="contentEditInput; else defaultMatChipEditInput"
select="[matChipEditInput]"></ng-content>
<ng-template #defaultMatChipEditInput><span matChipEditInput></span></ng-template>
</ng-container>

<span class="mat-mdc-chip-primary-focus-indicator mat-mdc-focus-indicator"></span>
</span>
<span class="mat-mdc-chip-primary-focus-indicator mat-mdc-focus-indicator" aria-hidden="true"></span>
</span>
</span>

Expand Down
10 changes: 6 additions & 4 deletions src/material/chips/chip-row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ describe('MDC-based Row Chips', () => {
return chipNativeElement.querySelector('.mat-chip-edit-input')!;
}

it('should set the role of the primary action based on whether it is editable', () => {
it('should set the role of the primary action to gridcell', () => {
testComponent.editable = false;
fixture.detectChanges();
expect(primaryAction.hasAttribute('role')).toBe(false);
expect(primaryAction.getAttribute('role')).toBe('gridcell');

testComponent.editable = true;
fixture.detectChanges();
expect(primaryAction.getAttribute('role')).toBe('button');
// Test regression of bug where element is mislabeled as a button role. Element that does not perform its
// action on click event is not a button by ARIA spec (#27106).
expect(primaryAction.getAttribute('role')).toBe('gridcell');
});

it('should not delete the chip on DELETE or BACKSPACE', () => {
Expand Down Expand Up @@ -346,7 +348,7 @@ describe('MDC-based Row Chips', () => {
fixture.detectChanges();

const primaryGridCell = (fixture.nativeElement as HTMLElement).querySelector(
'[role="gridcell"].mdc-evolution-chip__cell--primary .mat-mdc-chip-action',
'[role="gridcell"].mdc-evolution-chip__cell--primary.mat-mdc-chip-action',
);
expect(primaryGridCell)
.withContext('expected to find the grid cell for the primary chip action')
Expand Down
2 changes: 1 addition & 1 deletion src/material/chips/chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

// Ensures that the trailing icon is pushed to the end if the chip has a set width.
.mdc-evolution-chip__cell--primary {
width: 100%;
flex-basis: 100%;
}

// This element can be placed on a `button` node which usually has some user agent styles.
Expand Down