-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,8 +303,11 @@ export abstract class _MatSelectBase<C> | |
/** Emits whenever the component is destroyed. */ | ||
protected readonly _destroy = new Subject<void>(); | ||
|
||
/** The aria-describedby attribute on the select for improved a11y. */ | ||
_ariaDescribedby: string; | ||
/** | ||
* Implemented as part of MatFormFieldControl. | ||
* @docs-private | ||
*/ | ||
@Input('aria-describedby') userAriaDescribedBy: string; | ||
|
||
/** Deals with the selection logic. */ | ||
_selectionModel: SelectionModel<MatOption>; | ||
|
@@ -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']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change necessary? Since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without it, this test fails:
As a result of this PR (and #24292 for MatChipList and #19587 for MatInput), the So, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
this.stateChanges.next(); | ||
} | ||
|
||
|
@@ -1146,7 +1149,11 @@ export abstract class _MatSelectBase<C> | |
* @docs-private | ||
*/ | ||
setDescribedByIds(ids: string[]) { | ||
this._ariaDescribedby = ids.join(' '); | ||
if (ids.length) { | ||
this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' ')); | ||
} else { | ||
this._elementRef.nativeElement.removeAttribute('aria-describedby'); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -1191,7 +1198,6 @@ export abstract class _MatSelectBase<C> | |
'[attr.aria-required]': 'required.toString()', | ||
'[attr.aria-disabled]': 'disabled.toString()', | ||
'[attr.aria-invalid]': 'errorState', | ||
'[attr.aria-describedby]': '_ariaDescribedby || null', | ||
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()', | ||
'[class.mat-select-disabled]': 'disabled', | ||
'[class.mat-select-invalid]': 'errorState', | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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+$/);