From 0c62149e4984e456879d8949628b98144720565e Mon Sep 17 00:00:00 2001 From: crisbeto Date: Fri, 8 Dec 2017 20:05:52 +0100 Subject: [PATCH] fix(chips): being able to focus disabled chip by clicking Fixes users being able to focus a disabled chip by clicking it. Fixes #8883. --- src/lib/chips/chip.spec.ts | 17 +++++++++++------ src/lib/chips/chip.ts | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/chips/chip.spec.ts b/src/lib/chips/chip.spec.ts index e5bdd5023bab..86374192cb58 100644 --- a/src/lib/chips/chip.spec.ts +++ b/src/lib/chips/chip.spec.ts @@ -19,13 +19,9 @@ describe('Chips', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [MatChipsModule], - declarations: [ - BasicChip, SingleChip - ], + declarations: [BasicChip, SingleChip], providers: [{ - provide: Directionality, useFactory: () => { - return {value: dir}; - } + provide: Directionality, useFactory: () => ({value: dir}) }] }); @@ -281,6 +277,15 @@ describe('Chips', () => { expect(chipNativeElement.getAttribute('aria-disabled')).toBe('true'); }); + it('should make disabled chips non-focusable', () => { + expect(chipNativeElement.getAttribute('tabindex')).toBe('-1'); + + testComponent.disabled = true; + fixture.detectChanges(); + + expect(chipNativeElement.getAttribute('tabindex')).toBeFalsy(); + }); + }); }); }); diff --git a/src/lib/chips/chip.ts b/src/lib/chips/chip.ts index 2cbb6248c008..76c73b3afb10 100644 --- a/src/lib/chips/chip.ts +++ b/src/lib/chips/chip.ts @@ -68,7 +68,7 @@ export class MatBasicChip { exportAs: 'matChip', host: { 'class': 'mat-chip', - 'tabindex': '-1', + '[attr.tabindex]': 'disabled ? null : -1', 'role': 'option', '[class.mat-chip-selected]': 'selected', '[attr.disabled]': 'disabled || null',