From 76d9b89d58f60d98796fcb227d9904c593db268f Mon Sep 17 00:00:00 2001 From: MeAkib Date: Wed, 30 Sep 2026 09:50:30 +0600 Subject: [PATCH] refactor(material/sort): inject AriaDescriber as required `MatSortHeader` was injecting `AriaDescriber` as optional and guarding every call with optional chaining. `AriaDescriber` is always available since it's automatically provided, and `MatTooltip` and `MatBadge` already inject it as required, so we can drop the optional flag and the null checks. --- src/material/sort/sort-header.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/material/sort/sort-header.ts b/src/material/sort/sort-header.ts index ec1ee5d15fb1..7bbe1de997af 100644 --- a/src/material/sort/sort-header.ts +++ b/src/material/sort/sort-header.ts @@ -65,7 +65,7 @@ export class MatSortHeader implements MatSortable, OnDestroy, OnInit, AfterViewI private _changeDetectorRef = inject(ChangeDetectorRef); private _focusMonitor = inject(FocusMonitor); private _elementRef = inject>(ElementRef); - private _ariaDescriber = inject(AriaDescriber, {optional: true}); + private _ariaDescriber = inject(AriaDescriber); private _renderChanges: Subscription | undefined; protected _animationsDisabled = _animationsDisabled(); @@ -165,7 +165,7 @@ export class MatSortHeader implements MatSortable, OnDestroy, OnInit, AfterViewI this._renderChanges?.unsubscribe(); if (this._sortButton) { - this._ariaDescriber?.removeDescription(this._sortButton, this._sortActionDescription); + this._ariaDescriber.removeDescription(this._sortButton, this._sortActionDescription); } } @@ -226,9 +226,8 @@ export class MatSortHeader implements MatSortable, OnDestroy, OnInit, AfterViewI // nothing to update in the DOM. if (this._sortButton) { // removeDescription will no-op if there is no existing message. - // TODO(jelbourn): remove optional chaining when AriaDescriber is required. - this._ariaDescriber?.removeDescription(this._sortButton, this._sortActionDescription); - this._ariaDescriber?.describe(this._sortButton, newDescription); + this._ariaDescriber.removeDescription(this._sortButton, this._sortActionDescription); + this._ariaDescriber.describe(this._sortButton, newDescription); } this._sortActionDescription = newDescription;