mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(chip): add aria-selected to chip (#5920)
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user