Skip to content

Commit

Permalink
feat(material-experimental/mdc-chips): add unit tests for custom aria…
Browse files Browse the repository at this point in the history
…-describedby
  • Loading branch information
RobertAKARobin committed Jun 28, 2022
1 parent 755287a commit 8eb6706
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/material-experimental/mdc-chips/chip-listbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,12 @@ describe('MDC-based MatChipListbox', () => {

expect(chipArray[4].focus).not.toHaveBeenCalled();
});

it('should support user binding to `aria-describedby`', fakeAsync(() => {
chipListboxInstance.userAriaDescribedBy = 'test';
fixture.detectChanges();
expect(chipListboxNativeElement.getAttribute('aria-describedby')).toBe('test');
}));
});

describe('multiple selection', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/material-experimental/mdc-chips/chip-listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export const MAT_CHIP_LISTBOX_CONTROL_VALUE_ACCESSOR: any = {
'class': 'mdc-evolution-chip-set mat-mdc-chip-listbox',
'[attr.role]': 'role',
'[tabIndex]': 'empty ? -1 : tabIndex',
// TODO: replace this binding with use of AriaDescriber
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-required]': 'role ? required : null',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-multiselectable]': 'multiple',
Expand Down
6 changes: 6 additions & 0 deletions src/material-experimental/mdc-chips/chip-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ describe('MDC-based MatChipSet', () => {
fixture.detectChanges();
expect(chipSetNativeElement.getAttribute('role')).toBe('list');
});

it('should support user binding to `aria-describedby`', fakeAsync(() => {
chipSetInstance.userAriaDescribedBy = 'test';
fixture.detectChanges();
expect(chipSetNativeElement.getAttribute('aria-describedby')).toBe('test');
}));
});
});

Expand Down
12 changes: 12 additions & 0 deletions src/material-experimental/mdc-chips/chip-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const _MatChipSetMixinBase = mixinTabIndex(MatChipSetBase);
'class': 'mat-mdc-chip-set mdc-evolution-chip-set',
'(keydown)': '_handleKeydown($event)',
'[attr.role]': 'role',
'[attr.aria-describedby]': 'userAriaDescribedBy || null',
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
Expand Down Expand Up @@ -85,6 +86,17 @@ export class MatChipSet
return this._getChipStream(chip => chip.destroyed);
}

@Input('aria-describedby')
get userAriaDescribedBy(): string {
return this._userAriaDescribedBy;
}

set userAriaDescribedBy(userAriaDescribedBy: string) {
this._userAriaDescribedBy = userAriaDescribedBy;
}

private _userAriaDescribedBy: string;

/** Whether the chip set is disabled. */
@Input()
get disabled(): boolean {
Expand Down

0 comments on commit 8eb6706

Please sign in to comment.