Skip to content

Commit

Permalink
fix(cdk/platform): adjust return type for _getShadowRoot
Browse files Browse the repository at this point in the history
The return type for `_getShadowRoot` is actually a `ShadowRoot`, not a `Node`.
  • Loading branch information
crisbeto committed Feb 3, 2021
1 parent 155c7c2 commit caaa691
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const FOCUS_MONITOR_DEFAULT_OPTIONS =
type MonitoredElementInfo = {
checkChildren: boolean,
subject: Subject<FocusOrigin>,
rootNode: HTMLElement|Document
rootNode: HTMLElement|ShadowRoot|Document
};

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

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

// Check if we're already monitoring this element.
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ export class DragRef<T = any> {
*/
private _getShadowRoot(): ShadowRoot | null {
if (this._cachedShadowRoot === undefined) {
this._cachedShadowRoot = _getShadowRoot(this._rootElement) as ShadowRoot | null;
this._cachedShadowRoot = _getShadowRoot(this._rootElement);
}

return this._cachedShadowRoot;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/drop-list-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ export class DropListRef<T = any> {
*/
private _getShadowRoot(): DocumentOrShadowRoot {
if (!this._cachedShadowRoot) {
const shadowRoot = _getShadowRoot(coerceElement(this.element)) as ShadowRoot | null;
const shadowRoot = _getShadowRoot(coerceElement(this.element));
this._cachedShadowRoot = shadowRoot || this._document;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cdk/platform/features/shadow-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function _supportsShadowDom(): boolean {
}

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

Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/cdk/platform.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare function _getShadowRoot(element: HTMLElement): Node | null;
export declare function _getShadowRoot(element: HTMLElement): ShadowRoot | null;

export declare function _supportsShadowDom(): boolean;

Expand Down

0 comments on commit caaa691

Please sign in to comment.