MCPcopy Create free account
hub / github.com/angular/components / _syncDescribedByIds

Method _syncDescribedByIds

src/material/form-field/form-field.ts:759–809  ·  view source on GitHub ↗

* Sets the list of element IDs that describe the child control. This allows the control to update * its `aria-describedby` attribute accordingly.

()

Source from the content-addressed store, hash-verified

757 * its `aria-describedby` attribute accordingly.
758 */
759 private _syncDescribedByIds() {
760 if (this._control) {
761 let ids: string[] = [];
762
763 // TODO(wagnermaciel): Remove the type check when we find the root cause of this bug.
764 if (
765 this._control.userAriaDescribedBy &&
766 typeof this._control.userAriaDescribedBy === 'string'
767 ) {
768 ids.push(...this._control.userAriaDescribedBy.split(' '));
769 }
770
771 if (this._getSubscriptMessageType() === 'hint') {
772 const startHint = this._hintChildren
773 ? this._hintChildren.find(hint => hint.align === 'start')
774 : null;
775 const endHint = this._hintChildren
776 ? this._hintChildren.find(hint => hint.align === 'end')
777 : null;
778
779 if (startHint) {
780 ids.push(startHint.id);
781 } else if (this._hintLabel) {
782 ids.push(this._hintLabelId);
783 }
784
785 if (endHint) {
786 ids.push(endHint.id);
787 }
788 } else if (this._errorChildren) {
789 ids.push(...this._errorChildren.map(error => error.id));
790 }
791
792 const existingDescribedBy = this._control.describedByIds;
793 let toAssign: string[];
794
795 // In some cases there might be some `aria-describedby` IDs that were assigned directly,
796 // like by the `AriaDescriber` (see #30011). Attempt to preserve them by taking the previous
797 // attribute value and filtering out the IDs that came from the previous `setDescribedByIds`
798 // call. Note the `|| ids` here allows us to avoid duplicating IDs on the first render.
799 if (existingDescribedBy) {
800 const exclude = this._describedByIds || ids;
801 toAssign = ids.concat(existingDescribedBy.filter(id => id && !exclude.includes(id)));
802 } else {
803 toAssign = ids;
804 }
805
806 this._control.setDescribedByIds(toAssign);
807 this._describedByIds = ids;
808 }
809 }
810
811 /**
812 * Calculates the horizontal offset of the label in the outline appearance. In the outline

Callers 3

_initializeControlMethod · 0.95
_initializeSubscriptMethod · 0.95
_processHintsMethod · 0.95

Calls 4

pushMethod · 0.65
setDescribedByIdsMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected