Skip to content

Commit 8eb6706

Browse files
feat(material-experimental/mdc-chips): add unit tests for custom aria-describedby
1 parent 755287a commit 8eb6706

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

src/material-experimental/mdc-chips/chip-listbox.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ describe('MDC-based MatChipListbox', () => {
638638

639639
expect(chipArray[4].focus).not.toHaveBeenCalled();
640640
});
641+
642+
it('should support user binding to `aria-describedby`', fakeAsync(() => {
643+
chipListboxInstance.userAriaDescribedBy = 'test';
644+
fixture.detectChanges();
645+
expect(chipListboxNativeElement.getAttribute('aria-describedby')).toBe('test');
646+
}));
641647
});
642648

643649
describe('multiple selection', () => {

src/material-experimental/mdc-chips/chip-listbox.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ export const MAT_CHIP_LISTBOX_CONTROL_VALUE_ACCESSOR: any = {
6666
'class': 'mdc-evolution-chip-set mat-mdc-chip-listbox',
6767
'[attr.role]': 'role',
6868
'[tabIndex]': 'empty ? -1 : tabIndex',
69-
// TODO: replace this binding with use of AriaDescriber
70-
'[attr.aria-describedby]': '_ariaDescribedby || null',
7169
'[attr.aria-required]': 'role ? required : null',
7270
'[attr.aria-disabled]': 'disabled.toString()',
7371
'[attr.aria-multiselectable]': 'multiple',

src/material-experimental/mdc-chips/chip-set.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ describe('MDC-based MatChipSet', () => {
7575
fixture.detectChanges();
7676
expect(chipSetNativeElement.getAttribute('role')).toBe('list');
7777
});
78+
79+
it('should support user binding to `aria-describedby`', fakeAsync(() => {
80+
chipSetInstance.userAriaDescribedBy = 'test';
81+
fixture.detectChanges();
82+
expect(chipSetNativeElement.getAttribute('aria-describedby')).toBe('test');
83+
}));
7884
});
7985
});
8086

src/material-experimental/mdc-chips/chip-set.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const _MatChipSetMixinBase = mixinTabIndex(MatChipSetBase);
5555
'class': 'mat-mdc-chip-set mdc-evolution-chip-set',
5656
'(keydown)': '_handleKeydown($event)',
5757
'[attr.role]': 'role',
58+
'[attr.aria-describedby]': 'userAriaDescribedBy || null',
5859
},
5960
encapsulation: ViewEncapsulation.None,
6061
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -85,6 +86,17 @@ export class MatChipSet
8586
return this._getChipStream(chip => chip.destroyed);
8687
}
8788

89+
@Input('aria-describedby')
90+
get userAriaDescribedBy(): string {
91+
return this._userAriaDescribedBy;
92+
}
93+
94+
set userAriaDescribedBy(userAriaDescribedBy: string) {
95+
this._userAriaDescribedBy = userAriaDescribedBy;
96+
}
97+
98+
private _userAriaDescribedBy: string;
99+
88100
/** Whether the chip set is disabled. */
89101
@Input()
90102
get disabled(): boolean {

0 commit comments

Comments
 (0)