Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib/chips/chip.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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