Skip to content

Commit 281de25

Browse files
tinayuangaokara
authored andcommitted
feat(chip): add aria-selected to chip (#5920)
1 parent 266f237 commit 281de25

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/lib/chips/chip.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ describe('Chips', () => {
164164
expect(testComponent.chipDeselect).toHaveBeenCalledTimes(1);
165165
expect(testComponent.chipDeselect).toHaveBeenCalledWith(CHIP_EVENT);
166166
});
167+
168+
it('should have correct aria-selected', () => {
169+
expect(chipNativeElement.getAttribute('aria-selected')).toBe('false');
170+
171+
testComponent.selected = true;
172+
fixture.detectChanges();
173+
174+
expect(chipNativeElement.getAttribute('aria-selected')).toBe('true');
175+
});
167176
});
168177

169178
describe('when selectable is false', () => {
@@ -184,6 +193,15 @@ describe('Chips', () => {
184193
expect(chipInstance.selected).toBeFalsy();
185194
expect(testComponent.chipSelect).not.toHaveBeenCalled();
186195
});
196+
197+
it('should have empty aria-selected', () => {
198+
expect(chipNativeElement.getAttribute('aria-selected')).toBeFalsy();
199+
200+
testComponent.selectable = true;
201+
fixture.detectChanges();
202+
203+
expect(chipNativeElement.getAttribute('aria-selected')).toBe('false');
204+
});
187205
});
188206

189207
describe('when removable is true', () => {

src/lib/chips/chip.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class MdBasicChip { }
6060
'[class.mat-chip-selected]': 'selected',
6161
'[attr.disabled]': 'disabled || null',
6262
'[attr.aria-disabled]': 'disabled.toString()',
63+
'[attr.aria-selected]': 'ariaSelected',
6364
'(click)': '_handleClick($event)',
6465
'(keydown)': '_handleKeydown($event)',
6566
'(focus)': '_hasFocus = true',
@@ -118,6 +119,10 @@ export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, Ca
118119
/** Emitted when the chip is destroyed. */
119120
@Output() destroy = new EventEmitter<MdChipEvent>();
120121

122+
get ariaSelected(): string {
123+
return this.selectable ? this.selected.toString() : '';
124+
}
125+
121126
constructor(renderer: Renderer2, elementRef: ElementRef) {
122127
super(renderer, elementRef);
123128
}

0 commit comments

Comments
 (0)