* Sets the list of element IDs that describe the child control. This allows the control to update * its `aria-describedby` attribute accordingly.
()
| 693 | * its `aria-describedby` attribute accordingly. |
| 694 | */ |
| 695 | private _syncDescribedByIds() { |
| 696 | if (this._control) { |
| 697 | let ids: string[] = []; |
| 698 | |
| 699 | // TODO(wagnermaciel): Remove the type check when we find the root cause of this bug. |
| 700 | if ( |
| 701 | this._control.userAriaDescribedBy && |
| 702 | typeof this._control.userAriaDescribedBy === 'string' |
| 703 | ) { |
| 704 | ids.push(...this._control.userAriaDescribedBy.split(' ')); |
| 705 | } |
| 706 | |
| 707 | if (this._getSubscriptMessageType() === 'hint') { |
| 708 | const startHint = this._hintChildren |
| 709 | ? this._hintChildren.find(hint => hint.align === 'start') |
| 710 | : null; |
| 711 | const endHint = this._hintChildren |
| 712 | ? this._hintChildren.find(hint => hint.align === 'end') |
| 713 | : null; |
| 714 | |
| 715 | if (startHint) { |
| 716 | ids.push(startHint.id); |
| 717 | } else if (this._hintLabel) { |
| 718 | ids.push(this._hintLabelId); |
| 719 | } |
| 720 | |
| 721 | if (endHint) { |
| 722 | ids.push(endHint.id); |
| 723 | } |
| 724 | } else if (this._errorChildren) { |
| 725 | ids.push(...this._errorChildren.map(error => error.id)); |
| 726 | } |
| 727 | |
| 728 | const existingDescribedBy = this._control.describedByIds; |
| 729 | let toAssign: string[]; |
| 730 | |
| 731 | // In some cases there might be some `aria-describedby` IDs that were assigned directly, |
| 732 | // like by the `AriaDescriber` (see #30011). Attempt to preserve them by taking the previous |
| 733 | // attribute value and filtering out the IDs that came from the previous `setDescribedByIds` |
| 734 | // call. Note the `|| ids` here allows us to avoid duplicating IDs on the first render. |
| 735 | if (existingDescribedBy) { |
| 736 | const exclude = this._describedByIds || ids; |
| 737 | toAssign = ids.concat(existingDescribedBy.filter(id => id && !exclude.includes(id))); |
| 738 | } else { |
| 739 | toAssign = ids; |
| 740 | } |
| 741 | |
| 742 | this._control.setDescribedByIds(toAssign); |
| 743 | this._describedByIds = ids; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Calculates the horizontal offset of the label in the outline appearance. In the outline |
no test coverage detected