diff --git a/src/lib/chips/chip.spec.ts b/src/lib/chips/chip.spec.ts index cbf45dc3df7c..2eb10502f1ed 100644 --- a/src/lib/chips/chip.spec.ts +++ b/src/lib/chips/chip.spec.ts @@ -164,6 +164,15 @@ describe('Chips', () => { expect(testComponent.chipDeselect).toHaveBeenCalledTimes(1); expect(testComponent.chipDeselect).toHaveBeenCalledWith(CHIP_EVENT); }); + + it('should have correct aria-selected', () => { + expect(chipNativeElement.getAttribute('aria-selected')).toBe('false'); + + testComponent.selected = true; + fixture.detectChanges(); + + expect(chipNativeElement.getAttribute('aria-selected')).toBe('true'); + }); }); describe('when selectable is false', () => { @@ -184,6 +193,15 @@ describe('Chips', () => { expect(chipInstance.selected).toBeFalsy(); expect(testComponent.chipSelect).not.toHaveBeenCalled(); }); + + it('should have empty aria-selected', () => { + expect(chipNativeElement.getAttribute('aria-selected')).toBeFalsy(); + + testComponent.selectable = true; + fixture.detectChanges(); + + expect(chipNativeElement.getAttribute('aria-selected')).toBe('false'); + }); }); describe('when removable is true', () => { diff --git a/src/lib/chips/chip.ts b/src/lib/chips/chip.ts index f8a5b1c7a954..8befac669d6b 100644 --- a/src/lib/chips/chip.ts +++ b/src/lib/chips/chip.ts @@ -60,6 +60,7 @@ export class MdBasicChip { } '[class.mat-chip-selected]': 'selected', '[attr.disabled]': 'disabled || null', '[attr.aria-disabled]': 'disabled.toString()', + '[attr.aria-selected]': 'ariaSelected', '(click)': '_handleClick($event)', '(keydown)': '_handleKeydown($event)', '(focus)': '_hasFocus = true', @@ -118,6 +119,10 @@ export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, Ca /** Emitted when the chip is destroyed. */ @Output() destroy = new EventEmitter(); + get ariaSelected(): string { + return this.selectable ? this.selected.toString() : ''; + } + constructor(renderer: Renderer2, elementRef: ElementRef) { super(renderer, elementRef); }