feat(chip): add aria-selected to chip (#5920)

This commit is contained in:
tinayuangao
2017-07-21 11:37:47 -07:00
committed by Kara
parent 266f2370ca
commit 281de25b1b
2 changed files with 23 additions and 0 deletions
+18
View File
@@ -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', () => {
+5
View File
@@ -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<MdChipEvent>();
get ariaSelected(): string {
return this.selectable ? this.selected.toString() : '';
}
constructor(renderer: Renderer2, elementRef: ElementRef) {
super(renderer, elementRef);
}