Skip to content

Commit

Permalink
feat(chip): add aria-selected to chip (#5920)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao authored and kara committed Jul 21, 2017
1 parent 266f237 commit 281de25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib/chips/chip.spec.ts
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/chips/chip.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 281de25

Please sign in to comment.