Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(material/select): allow user-defined aria-describedby #24644

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

RobertAKARobin
Copy link
Contributor

Based on #24292.

Further fixes #16209.

@RobertAKARobin RobertAKARobin requested review from a team and crisbeto as code owners March 22, 2022 16:32
@RobertAKARobin
Copy link
Contributor Author

I suspect ci/circleci: e2e_tests just needs to be rerun.

@@ -611,7 +614,7 @@ export abstract class _MatSelectBase<C>
ngOnChanges(changes: SimpleChanges) {
// Updating the disabled state is handled by `mixinDisabled`, but we need to additionally let
// the parent form field know to run change detection when the disabled state changes.
if (changes['disabled']) {
if (changes['disabled'] || changes['userAriaDescribedBy']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary? Since the aria-describedby is on the select it shouldn't be required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, this test fails:

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

As a result of this PR (and #24292 for MatChipList and #19587 for MatInput), the aria-describedby is no longer set in @Component({ host }). Rather, it is set using nativeElement.setAttribute in MatSelect#setDescribedByIds, which is called by MatFormField#_syncDescribedByIds, which in turn is called when stateChanges updates.

So, userAriaDescribedBy has to trigger a stateChanges.next() in order for the aria-describedby to actually be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and for that matter, MatChipList needs unit tests for this too! I've submitted #24657. In that one I used a setter for userAriaDescribedBy to call stateChanges.next(). Let me know if you'd prefer that here too.

fixture.componentInstance.hint = 'test';
fixture.detectChanges();
const hint = fixture.debugElement.query(By.css('mat-hint')).nativeElement;
expect(select.getAttribute('aria-describedby')).toBe(hint.getAttribute('id'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you can drop this assertion since it's covered by the one below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This asserts that it's exactly the same as the hint's ID, whereas the next assertion asserts only that it matches a certain format: expect(select.getAttribute('aria-describedby')).toMatch(/^mat-mdc-hint-\d+$/);

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Apr 16, 2022
@zarend zarend added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Apr 19, 2022
@andrewseguin andrewseguin merged commit 1aa5a20 into angular:master Apr 20, 2022
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mat-hint causing an ExpressionChangedAfterItHasBeenCheckedError if respective input has a *ngIf directive
4 participants