Skip to content

Commit 70c75ea

Browse files
crisbetojelbourn
authored andcommitted
fix(chips): being able to focus disabled chip by clicking (#8892)
Fixes users being able to focus a disabled chip by clicking it. Fixes #8883.
1 parent 329f19a commit 70c75ea

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/lib/chips/chip.spec.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ describe('Chips', () => {
1919
beforeEach(async(() => {
2020
TestBed.configureTestingModule({
2121
imports: [MatChipsModule],
22-
declarations: [
23-
BasicChip, SingleChip
24-
],
22+
declarations: [BasicChip, SingleChip],
2523
providers: [{
26-
provide: Directionality, useFactory: () => {
27-
return {value: dir};
28-
}
24+
provide: Directionality, useFactory: () => ({value: dir})
2925
}]
3026
});
3127

@@ -281,6 +277,15 @@ describe('Chips', () => {
281277
expect(chipNativeElement.getAttribute('aria-disabled')).toBe('true');
282278
});
283279

280+
it('should make disabled chips non-focusable', () => {
281+
expect(chipNativeElement.getAttribute('tabindex')).toBe('-1');
282+
283+
testComponent.disabled = true;
284+
fixture.detectChanges();
285+
286+
expect(chipNativeElement.getAttribute('tabindex')).toBeFalsy();
287+
});
288+
284289
});
285290
});
286291
});

src/lib/chips/chip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class MatBasicChip {
6868
exportAs: 'matChip',
6969
host: {
7070
'class': 'mat-chip',
71-
'tabindex': '-1',
71+
'[attr.tabindex]': 'disabled ? null : -1',
7272
'role': 'option',
7373
'[class.mat-chip-selected]': 'selected',
7474
'[attr.disabled]': 'disabled || null',

0 commit comments

Comments
 (0)