Skip to content

Commit 78c6eda

Browse files
crisbetoannieyw
authored andcommitted
fix(cdk/platform): adjust return type for _getShadowRoot (#21798)
The return type for `_getShadowRoot` is actually a `ShadowRoot`, not a `Node`. (cherry picked from commit 6fee271)
1 parent 8d7c56a commit 78c6eda

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

src/cdk/a11y/focus-monitor/focus-monitor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const FOCUS_MONITOR_DEFAULT_OPTIONS =
6969
type MonitoredElementInfo = {
7070
checkChildren: boolean,
7171
subject: Subject<FocusOrigin>,
72-
rootNode: HTMLElement|Document
72+
rootNode: HTMLElement|ShadowRoot|Document
7373
};
7474

7575
/**
@@ -118,7 +118,7 @@ export class FocusMonitor implements OnDestroy {
118118
* handlers differently from the rest of the events, because the browser won't emit events
119119
* to the document when focus moves inside of a shadow root.
120120
*/
121-
private _rootNodeFocusListenerCount = new Map<HTMLElement|Document, number>();
121+
private _rootNodeFocusListenerCount = new Map<HTMLElement|Document|ShadowRoot, number>();
122122

123123
/**
124124
* The specified detection mode, used for attributing the origin of a focus
@@ -235,7 +235,7 @@ export class FocusMonitor implements OnDestroy {
235235
// If the element is inside the shadow DOM, we need to bind our focus/blur listeners to
236236
// the shadow root, rather than the `document`, because the browser won't emit focus events
237237
// to the `document`, if focus is moving within the same shadow root.
238-
const rootNode = (_getShadowRoot(nativeElement) as HTMLElement|null) || this._getDocument();
238+
const rootNode = _getShadowRoot(nativeElement) || this._getDocument();
239239
const cachedInfo = this._elementInfo.get(nativeElement);
240240

241241
// Check if we're already monitoring this element.

src/cdk/drag-drop/drag-ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ export class DragRef<T = any> {
13531353
*/
13541354
private _getShadowRoot(): ShadowRoot | null {
13551355
if (this._cachedShadowRoot === undefined) {
1356-
this._cachedShadowRoot = _getShadowRoot(this._rootElement) as ShadowRoot | null;
1356+
this._cachedShadowRoot = _getShadowRoot(this._rootElement);
13571357
}
13581358

13591359
return this._cachedShadowRoot;

src/cdk/drag-drop/drop-list-ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ export class DropListRef<T = any> {
923923
*/
924924
private _getShadowRoot(): DocumentOrShadowRoot {
925925
if (!this._cachedShadowRoot) {
926-
const shadowRoot = _getShadowRoot(coerceElement(this.element)) as ShadowRoot | null;
926+
const shadowRoot = _getShadowRoot(coerceElement(this.element));
927927
this._cachedShadowRoot = shadowRoot || this._document;
928928
}
929929

src/cdk/platform/features/shadow-dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function _supportsShadowDom(): boolean {
1919
}
2020

2121
/** Gets the shadow root of an element, if supported and the element is inside the Shadow DOM. */
22-
export function _getShadowRoot(element: HTMLElement): Node | null {
22+
export function _getShadowRoot(element: HTMLElement): ShadowRoot | null {
2323
if (_supportsShadowDom()) {
2424
const rootNode = element.getRootNode ? element.getRootNode() : null;
2525

src/material/progress-spinner/progress-spinner.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ describe('MatProgressSpinner', () => {
421421
fixture.detectChanges();
422422

423423
const spinner = fixture.debugElement.query(By.css('mat-progress-spinner'))!.nativeElement;
424-
const shadowRoot = _getShadowRoot(spinner) as HTMLElement;
424+
const shadowRoot = _getShadowRoot(spinner)!;
425425

426426
expect(shadowRoot.querySelector('style[mat-spinner-animation="27"]')).toBeTruthy();
427427

@@ -442,7 +442,7 @@ describe('MatProgressSpinner', () => {
442442
fixture.detectChanges();
443443

444444
const spinner = fixture.debugElement.query(By.css('mat-progress-spinner'))!.nativeElement;
445-
const shadowRoot = _getShadowRoot(spinner) as HTMLElement;
445+
const shadowRoot = _getShadowRoot(spinner)!;
446446

447447
expect(shadowRoot.querySelectorAll('style[mat-spinner-animation="39"]').length).toBe(1);
448448

@@ -473,7 +473,7 @@ describe('MatProgressSpinner', () => {
473473
fixture.detectChanges();
474474

475475
const spinner = fixture.componentInstance.spinner.nativeElement;
476-
const shadowRoot = _getShadowRoot(spinner) as HTMLElement;
476+
const shadowRoot = _getShadowRoot(spinner)!;
477477

478478
expect(shadowRoot.querySelector('style[mat-spinner-animation="27"]')).toBeTruthy();
479479

tools/public_api_guard/cdk/platform.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export declare function _getShadowRoot(element: HTMLElement): Node | null;
1+
export declare function _getShadowRoot(element: HTMLElement): ShadowRoot | null;
22

33
export declare function _supportsShadowDom(): boolean;
44

0 commit comments

Comments
 (0)