@skyux/core 5.9.2 → 5.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -137,6 +137,9 @@
137
137
  * @return Returns `true` if a child element with autofocus is found.
138
138
  */
139
139
  SkyCoreAdapterService.prototype.applyAutoFocus = function (elementRef) {
140
+ if (!elementRef) {
141
+ return false;
142
+ }
140
143
  var elementWithAutoFocus = elementRef.nativeElement.querySelector('[autofocus]');
141
144
  // Child was found with the autofocus property. Set focus and return true.
142
145
  if (elementWithAutoFocus) {
@@ -160,11 +163,13 @@
160
163
  SkyCoreAdapterService.prototype.getFocusableChildrenAndApplyFocus = function (elementRef, containerSelector, focusOnContainerIfNoChildrenFound) {
161
164
  if (focusOnContainerIfNoChildrenFound === void 0) { focusOnContainerIfNoChildrenFound = false; }
162
165
  var containerElement = elementRef.nativeElement.querySelector(containerSelector);
163
- var focusableChildren = this.getFocusableChildren(containerElement);
164
- // Focus first focusable child if available. Otherwise, set focus on container.
165
- if (!this.focusFirstElement(focusableChildren) &&
166
- focusOnContainerIfNoChildrenFound) {
167
- containerElement.focus();
166
+ if (containerElement) {
167
+ var focusableChildren = this.getFocusableChildren(containerElement);
168
+ // Focus first focusable child if available. Otherwise, set focus on container.
169
+ if (!this.focusFirstElement(focusableChildren) &&
170
+ focusOnContainerIfNoChildrenFound) {
171
+ containerElement.focus();
172
+ }
168
173
  }
169
174
  };
170
175
  /**
@@ -175,6 +180,9 @@
175
180
  */
176
181
  SkyCoreAdapterService.prototype.getFocusableChildren = function (element, options) {
177
182
  var _this = this;
183
+ if (!element) {
184
+ return [];
185
+ }
178
186
  var elements = Array.prototype.slice.call(element.querySelectorAll(SKY_TABBABLE_SELECTOR));
179
187
  // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.
180
188
  if (!options || !options.ignoreTabIndex) {
@@ -1843,7 +1843,7 @@
1843
1843
  "sources": [
1844
1844
  {
1845
1845
  "fileName": "projects/core/src/modules/adapter-service/adapter.service.ts",
1846
- "line": 147,
1846
+ "line": 154,
1847
1847
  "character": 9
1848
1848
  }
1849
1849
  ],
@@ -1915,7 +1915,7 @@
1915
1915
  "sources": [
1916
1916
  {
1917
1917
  "fileName": "projects/core/src/modules/adapter-service/adapter.service.ts",
1918
- "line": 123,
1918
+ "line": 127,
1919
1919
  "character": 9
1920
1920
  }
1921
1921
  ],
@@ -2000,7 +2000,7 @@
2000
2000
  "sources": [
2001
2001
  {
2002
2002
  "fileName": "projects/core/src/modules/adapter-service/adapter.service.ts",
2003
- "line": 176,
2003
+ "line": 187,
2004
2004
  "character": 9
2005
2005
  }
2006
2006
  ],
@@ -2056,7 +2056,7 @@
2056
2056
  "sources": [
2057
2057
  {
2058
2058
  "fileName": "projects/core/src/modules/adapter-service/adapter.service.ts",
2059
- "line": 185,
2059
+ "line": 196,
2060
2060
  "character": 9
2061
2061
  }
2062
2062
  ],
@@ -2122,7 +2122,7 @@
2122
2122
  "sources": [
2123
2123
  {
2124
2124
  "fileName": "projects/core/src/modules/adapter-service/adapter.service.ts",
2125
- "line": 219,
2125
+ "line": 230,
2126
2126
  "character": 9
2127
2127
  }
2128
2128
  ],
@@ -2263,7 +2263,7 @@
2263
2263
  "sources": [
2264
2264
  {
2265
2265
  "fileName": "projects/core/src/modules/adapter-service/adapter.service.ts",
2266
- "line": 236,
2266
+ "line": 247,
2267
2267
  "character": 9
2268
2268
  }
2269
2269
  ],
@@ -73,6 +73,9 @@ export class SkyCoreAdapterService {
73
73
  * @return Returns `true` if a child element with autofocus is found.
74
74
  */
75
75
  applyAutoFocus(elementRef) {
76
+ if (!elementRef) {
77
+ return false;
78
+ }
76
79
  const elementWithAutoFocus = elementRef.nativeElement.querySelector('[autofocus]');
77
80
  // Child was found with the autofocus property. Set focus and return true.
78
81
  if (elementWithAutoFocus) {
@@ -95,11 +98,13 @@ export class SkyCoreAdapterService {
95
98
  */
96
99
  getFocusableChildrenAndApplyFocus(elementRef, containerSelector, focusOnContainerIfNoChildrenFound = false) {
97
100
  const containerElement = elementRef.nativeElement.querySelector(containerSelector);
98
- const focusableChildren = this.getFocusableChildren(containerElement);
99
- // Focus first focusable child if available. Otherwise, set focus on container.
100
- if (!this.focusFirstElement(focusableChildren) &&
101
- focusOnContainerIfNoChildrenFound) {
102
- containerElement.focus();
101
+ if (containerElement) {
102
+ const focusableChildren = this.getFocusableChildren(containerElement);
103
+ // Focus first focusable child if available. Otherwise, set focus on container.
104
+ if (!this.focusFirstElement(focusableChildren) &&
105
+ focusOnContainerIfNoChildrenFound) {
106
+ containerElement.focus();
107
+ }
103
108
  }
104
109
  }
105
110
  /**
@@ -109,6 +114,9 @@ export class SkyCoreAdapterService {
109
114
  * @param options - Options for getting focusable children.
110
115
  */
111
116
  getFocusableChildren(element, options) {
117
+ if (!element) {
118
+ return [];
119
+ }
112
120
  let elements = Array.prototype.slice.call(element.querySelectorAll(SKY_TABBABLE_SELECTOR));
113
121
  // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.
114
122
  if (!options || !options.ignoreTabIndex) {
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/adapter-service/adapter.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEV,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;;AAIvE,MAAM,qBAAqB,GAAG;IAC5B,SAAS;IACT,YAAY;IACZ,uBAAuB;IACvB,wBAAwB;IACxB,wBAAwB;IACxB,0BAA0B;IAC1B,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,yCAAyC;IACzC,6BAA6B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAKb,MAAM,OAAO,qBAAqB;IAGhC,YAAoB,eAAiC;QAAjC,oBAAe,GAAf,eAAe,CAAkB;QACnD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,C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,OAAO,CAAC,WAAW;YACnB,OAAO,CAAC,YAAY;YACpB,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,CAChC,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;;mHAlPU,qBAAqB;uHAArB,qBAAqB,cAFpB,MAAM;4FAEP,qBAAqB;kBAHjC,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import {\n ElementRef,\n Injectable,\n Renderer2,\n RendererFactory2,\n} from '@angular/core';\n\nimport { SkyMediaBreakpoints } from '../media-query/media-breakpoints';\n\nimport { SkyFocusableChildrenOptions } from './focusable-children-options';\n\nconst SKY_TABBABLE_SELECTOR = [\n 'a[href]',\n 'area[href]',\n 'input:not([disabled])',\n 'button:not([disabled])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'iframe',\n 'object',\n 'embed',\n '*[contenteditable=true]:not([disabled])',\n '*[tabindex]:not([disabled])',\n].join(', ');\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyCoreAdapterService {\n private renderer: Renderer2;\n\n constructor(private rendererFactory: RendererFactory2) {\n this.renderer = this.rendererFactory.createRenderer(undefined, undefined);\n }\n\n /**\n * Set the responsive container CSS class for a given element.\n *\n * @param elementRef - The element that will recieve the new CSS class.\n * @param breakpoint - The SkyMediaBreakpoint will determine which class\n * gets set. For example a SkyMediaBreakpoint of `xs` will set a CSS class of `sky-responsive-container-xs`.\n */\n public setResponsiveContainerClass(\n elementRef: ElementRef,\n breakpoint: SkyMediaBreakpoints\n ): void {\n const nativeEl: HTMLElement = elementRef.nativeElement;\n\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-xs');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-sm');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-md');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-lg');\n\n let newClass: string;\n\n switch (breakpoint) {\n case SkyMediaBreakpoints.xs: {\n newClass = 'sky-responsive-container-xs';\n break;\n }\n case SkyMediaBreakpoints.sm: {\n newClass = 'sky-responsive-container-sm';\n break;\n }\n case SkyMediaBreakpoints.md: {\n newClass = 'sky-responsive-container-md';\n break;\n }\n default: {\n newClass = 'sky-responsive-container-lg';\n break;\n }\n }\n\n this.renderer.addClass(nativeEl, newClass);\n }\n\n /**\n * This method temporarily enables/disables pointer events.\n * This is helpful to prevent iFrames from interfering with drag events.\n *\n * @param enable - Set to `true` to enable pointer events. Set to `false` to disable.\n */\n public toggleIframePointerEvents(enable: boolean): void {\n const iframes = document.querySelectorAll('iframe');\n for (let i = 0; i < iframes.length; i++) {\n // Setting to empty string will allow iframe to fall back to its prior CSS assignment.\n iframes[i].style.pointerEvents = enable ? '' : 'none';\n }\n }\n\n /**\n * Focuses on the first element found with an `autofocus` attribute inside the supplied `elementRef`.\n *\n * @param elementRef - The element to search within.\n * @return Returns `true` if a child element with autofocus is found.\n */\n public applyAutoFocus(elementRef: ElementRef): boolean {\n const elementWithAutoFocus =\n elementRef.nativeElement.querySelector('[autofocus]');\n\n // Child was found with the autofocus property. Set focus and return true.\n if (elementWithAutoFocus) {\n elementWithAutoFocus.focus();\n return true;\n }\n\n // No children were found with autofocus property. Return false.\n return false;\n }\n\n /**\n * Sets focus on the first focusable child of the `elementRef` parameter.\n * If no focusable children are found, and `focusOnContainerIfNoChildrenFound` is `true`,\n * focus will be set on the container element.\n *\n * @param elementRef - The element to search within.\n * @param containerSelector - A CSS selector indicating the container that should\n * recieve focus if no focusable children are found.\n * @param focusOnContainerIfNoChildrenFound - It set to `true`, the container will\n * recieve focus if no focusable children are found.\n */\n public getFocusableChildrenAndApplyFocus(\n elementRef: ElementRef,\n containerSelector: string,\n focusOnContainerIfNoChildrenFound: boolean = false\n ): void {\n const containerElement =\n elementRef.nativeElement.querySelector(containerSelector);\n const focusableChildren = this.getFocusableChildren(containerElement);\n\n // Focus first focusable child if available. Otherwise, set focus on container.\n if (\n !this.focusFirstElement(focusableChildren) &&\n focusOnContainerIfNoChildrenFound\n ) {\n containerElement.focus();\n }\n }\n\n /**\n * Returns an array of all focusable children of provided `element`.\n *\n * @param element - The HTMLElement to search within.\n * @param options - Options for getting focusable children.\n */\n public getFocusableChildren(\n element: HTMLElement,\n options?: SkyFocusableChildrenOptions\n ): HTMLElement[] {\n let elements = Array.prototype.slice.call(\n element.querySelectorAll(SKY_TABBABLE_SELECTOR)\n );\n\n // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.\n if (!options || !options.ignoreTabIndex) {\n elements = elements.filter((el: HTMLElement) => {\n return el.tabIndex !== -1;\n });\n }\n\n // Unless ignoreVisibility = true, filter out elements that are not visible.\n if (!options || !options.ignoreVisibility) {\n elements = elements.filter((el: HTMLElement) => {\n return this.isVisible(el);\n });\n }\n\n return elements;\n }\n\n /**\n * Returns the clientWidth of the provided elementRef.\n * @param elementRef - The element to calculate width from.\n */\n public getWidth(elementRef: ElementRef): number {\n return elementRef.nativeElement.clientWidth;\n }\n\n /**\n * Checks if an event target has a higher z-index than a given element.\n * @param target The event target element.\n * @param element The element to test against. A z-index must be explicitly set for this element.\n */\n public isTargetAboveElement(\n target: EventTarget,\n element: HTMLElement\n ): boolean {\n const zIndex: string = getComputedStyle(element).zIndex;\n\n let el: HTMLElement = target as HTMLElement;\n\n while (el) {\n // Getting the computed style only works for elements that exist in the DOM.\n // In certain scenarios, an element is removed after a click event; by the time the event\n // bubbles up to other elements, however, the element has been removed and the computed style returns empty.\n // In this case, we'll need to check the z-index directly, via the style property.\n const targetZIndex: string =\n getComputedStyle(el).zIndex || el.style.zIndex;\n if (\n targetZIndex !== '' &&\n targetZIndex !== 'auto' &&\n +targetZIndex > +zIndex\n ) {\n return true;\n }\n\n el = el.parentElement as HTMLElement;\n }\n\n return false;\n }\n\n /**\n * Remove inline height styles from the provided elements.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for removing height.\n */\n public resetHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n for (let i = 0; i < children.length; i++) {\n // Setting style attributes with Web API requires null instead of undefined.\n // tslint:disable-next-line: no-null-keyword\n children[i].style.height = null;\n }\n }\n }\n\n /**\n * Sets all element heights to match the height of the tallest element.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for syncing height.\n */\n public syncMaxHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n let maxHeight = 0;\n for (let i = 0; i < children.length; i++) {\n maxHeight = Math.max(maxHeight, children[i].offsetHeight);\n }\n for (let i = 0; i < children.length; i++) {\n children[i].style.height = maxHeight + 'px';\n }\n }\n }\n\n private focusFirstElement(list: Array<HTMLElement>): boolean {\n if (list.length > 0) {\n list[0].focus();\n return true;\n }\n return false;\n }\n\n private isVisible(element: HTMLElement): boolean {\n const style = window.getComputedStyle(element);\n const isHidden = style.display === 'none' || style.visibility === 'hidden';\n if (isHidden) {\n return false;\n }\n\n const hasBounds = !!(\n element.offsetWidth ||\n element.offsetHeight ||\n element.getClientRects().length\n );\n return hasBounds;\n }\n}\n"]}
1
+ {"version":3,"file":"adapter.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/adapter-service/adapter.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEV,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;;AAIvE,MAAM,qBAAqB,GAAG;IAC5B,SAAS;IACT,YAAY;IACZ,uBAAuB;IACvB,wBAAwB;IACxB,wBAAwB;IACxB,0BAA0B;IAC1B,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,yCAAyC;IACzC,6BAA6B;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAKb,MAAM,OAAO,qBAAqB;IAGhC,YAAoB,eAAiC;QAAjC,oBAAe,GAAf,eAAe,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AAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,KAAK,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC;QAC3E,IAAI,QAAQ,EAAE;YACZ,OAAO,KAAK,CAAC;SACd;QAED,MAAM,SAAS,GAAG,CAAC,CAAC,CAClB,OAAO,CAAC,WAAW;YACnB,OAAO,CAAC,YAAY;YACpB,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,CAChC,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;;mHA7PU,qBAAqB;uHAArB,qBAAqB,cAFpB,MAAM;4FAEP,qBAAqB;kBAHjC,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import {\n ElementRef,\n Injectable,\n Renderer2,\n RendererFactory2,\n} from '@angular/core';\n\nimport { SkyMediaBreakpoints } from '../media-query/media-breakpoints';\n\nimport { SkyFocusableChildrenOptions } from './focusable-children-options';\n\nconst SKY_TABBABLE_SELECTOR = [\n 'a[href]',\n 'area[href]',\n 'input:not([disabled])',\n 'button:not([disabled])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'iframe',\n 'object',\n 'embed',\n '*[contenteditable=true]:not([disabled])',\n '*[tabindex]:not([disabled])',\n].join(', ');\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyCoreAdapterService {\n private renderer: Renderer2;\n\n constructor(private rendererFactory: RendererFactory2) {\n this.renderer = this.rendererFactory.createRenderer(undefined, undefined);\n }\n\n /**\n * Set the responsive container CSS class for a given element.\n *\n * @param elementRef - The element that will recieve the new CSS class.\n * @param breakpoint - The SkyMediaBreakpoint will determine which class\n * gets set. For example a SkyMediaBreakpoint of `xs` will set a CSS class of `sky-responsive-container-xs`.\n */\n public setResponsiveContainerClass(\n elementRef: ElementRef,\n breakpoint: SkyMediaBreakpoints\n ): void {\n const nativeEl: HTMLElement = elementRef.nativeElement;\n\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-xs');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-sm');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-md');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-lg');\n\n let newClass: string;\n\n switch (breakpoint) {\n case SkyMediaBreakpoints.xs: {\n newClass = 'sky-responsive-container-xs';\n break;\n }\n case SkyMediaBreakpoints.sm: {\n newClass = 'sky-responsive-container-sm';\n break;\n }\n case SkyMediaBreakpoints.md: {\n newClass = 'sky-responsive-container-md';\n break;\n }\n default: {\n newClass = 'sky-responsive-container-lg';\n break;\n }\n }\n\n this.renderer.addClass(nativeEl, newClass);\n }\n\n /**\n * This method temporarily enables/disables pointer events.\n * This is helpful to prevent iFrames from interfering with drag events.\n *\n * @param enable - Set to `true` to enable pointer events. Set to `false` to disable.\n */\n public toggleIframePointerEvents(enable: boolean): void {\n const iframes = document.querySelectorAll('iframe');\n for (let i = 0; i < iframes.length; i++) {\n // Setting to empty string will allow iframe to fall back to its prior CSS assignment.\n iframes[i].style.pointerEvents = enable ? '' : 'none';\n }\n }\n\n /**\n * Focuses on the first element found with an `autofocus` attribute inside the supplied `elementRef`.\n *\n * @param elementRef - The element to search within.\n * @return Returns `true` if a child element with autofocus is found.\n */\n public applyAutoFocus(elementRef: ElementRef): boolean {\n if (!elementRef) {\n return false;\n }\n\n const elementWithAutoFocus =\n elementRef.nativeElement.querySelector('[autofocus]');\n\n // Child was found with the autofocus property. Set focus and return true.\n if (elementWithAutoFocus) {\n elementWithAutoFocus.focus();\n return true;\n }\n\n // No children were found with autofocus property. Return false.\n return false;\n }\n\n /**\n * Sets focus on the first focusable child of the `elementRef` parameter.\n * If no focusable children are found, and `focusOnContainerIfNoChildrenFound` is `true`,\n * focus will be set on the container element.\n *\n * @param elementRef - The element to search within.\n * @param containerSelector - A CSS selector indicating the container that should\n * recieve focus if no focusable children are found.\n * @param focusOnContainerIfNoChildrenFound - It set to `true`, the container will\n * recieve focus if no focusable children are found.\n */\n public getFocusableChildrenAndApplyFocus(\n elementRef: ElementRef,\n containerSelector: string,\n focusOnContainerIfNoChildrenFound: boolean = false\n ): void {\n const containerElement =\n elementRef.nativeElement.querySelector(containerSelector);\n\n if (containerElement) {\n const focusableChildren = this.getFocusableChildren(containerElement);\n\n // Focus first focusable child if available. Otherwise, set focus on container.\n if (\n !this.focusFirstElement(focusableChildren) &&\n focusOnContainerIfNoChildrenFound\n ) {\n containerElement.focus();\n }\n }\n }\n\n /**\n * Returns an array of all focusable children of provided `element`.\n *\n * @param element - The HTMLElement to search within.\n * @param options - Options for getting focusable children.\n */\n public getFocusableChildren(\n element: HTMLElement,\n options?: SkyFocusableChildrenOptions\n ): HTMLElement[] {\n if (!element) {\n return [];\n }\n\n let elements = Array.prototype.slice.call(\n element.querySelectorAll(SKY_TABBABLE_SELECTOR)\n );\n\n // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.\n if (!options || !options.ignoreTabIndex) {\n elements = elements.filter((el: HTMLElement) => {\n return el.tabIndex !== -1;\n });\n }\n\n // Unless ignoreVisibility = true, filter out elements that are not visible.\n if (!options || !options.ignoreVisibility) {\n elements = elements.filter((el: HTMLElement) => {\n return this.isVisible(el);\n });\n }\n\n return elements;\n }\n\n /**\n * Returns the clientWidth of the provided elementRef.\n * @param elementRef - The element to calculate width from.\n */\n public getWidth(elementRef: ElementRef): number {\n return elementRef.nativeElement.clientWidth;\n }\n\n /**\n * Checks if an event target has a higher z-index than a given element.\n * @param target The event target element.\n * @param element The element to test against. A z-index must be explicitly set for this element.\n */\n public isTargetAboveElement(\n target: EventTarget,\n element: HTMLElement\n ): boolean {\n const zIndex: string = getComputedStyle(element).zIndex;\n\n let el: HTMLElement = target as HTMLElement;\n\n while (el) {\n // Getting the computed style only works for elements that exist in the DOM.\n // In certain scenarios, an element is removed after a click event; by the time the event\n // bubbles up to other elements, however, the element has been removed and the computed style returns empty.\n // In this case, we'll need to check the z-index directly, via the style property.\n const targetZIndex: string =\n getComputedStyle(el).zIndex || el.style.zIndex;\n if (\n targetZIndex !== '' &&\n targetZIndex !== 'auto' &&\n +targetZIndex > +zIndex\n ) {\n return true;\n }\n\n el = el.parentElement as HTMLElement;\n }\n\n return false;\n }\n\n /**\n * Remove inline height styles from the provided elements.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for removing height.\n */\n public resetHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n for (let i = 0; i < children.length; i++) {\n // Setting style attributes with Web API requires null instead of undefined.\n // tslint:disable-next-line: no-null-keyword\n children[i].style.height = null;\n }\n }\n }\n\n /**\n * Sets all element heights to match the height of the tallest element.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for syncing height.\n */\n public syncMaxHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n let maxHeight = 0;\n for (let i = 0; i < children.length; i++) {\n maxHeight = Math.max(maxHeight, children[i].offsetHeight);\n }\n for (let i = 0; i < children.length; i++) {\n children[i].style.height = maxHeight + 'px';\n }\n }\n }\n\n private focusFirstElement(list: Array<HTMLElement>): boolean {\n if (list.length > 0) {\n list[0].focus();\n return true;\n }\n return false;\n }\n\n private isVisible(element: HTMLElement): boolean {\n const style = window.getComputedStyle(element);\n const isHidden = style.display === 'none' || style.visibility === 'hidden';\n if (isHidden) {\n return false;\n }\n\n const hasBounds = !!(\n element.offsetWidth ||\n element.offsetHeight ||\n element.getClientRects().length\n );\n return hasBounds;\n }\n}\n"]}
@@ -116,6 +116,9 @@ class SkyCoreAdapterService {
116
116
  * @return Returns `true` if a child element with autofocus is found.
117
117
  */
118
118
  applyAutoFocus(elementRef) {
119
+ if (!elementRef) {
120
+ return false;
121
+ }
119
122
  const elementWithAutoFocus = elementRef.nativeElement.querySelector('[autofocus]');
120
123
  // Child was found with the autofocus property. Set focus and return true.
121
124
  if (elementWithAutoFocus) {
@@ -138,11 +141,13 @@ class SkyCoreAdapterService {
138
141
  */
139
142
  getFocusableChildrenAndApplyFocus(elementRef, containerSelector, focusOnContainerIfNoChildrenFound = false) {
140
143
  const containerElement = elementRef.nativeElement.querySelector(containerSelector);
141
- const focusableChildren = this.getFocusableChildren(containerElement);
142
- // Focus first focusable child if available. Otherwise, set focus on container.
143
- if (!this.focusFirstElement(focusableChildren) &&
144
- focusOnContainerIfNoChildrenFound) {
145
- containerElement.focus();
144
+ if (containerElement) {
145
+ const focusableChildren = this.getFocusableChildren(containerElement);
146
+ // Focus first focusable child if available. Otherwise, set focus on container.
147
+ if (!this.focusFirstElement(focusableChildren) &&
148
+ focusOnContainerIfNoChildrenFound) {
149
+ containerElement.focus();
150
+ }
146
151
  }
147
152
  }
148
153
  /**
@@ -152,6 +157,9 @@ class SkyCoreAdapterService {
152
157
  * @param options - Options for getting focusable children.
153
158
  */
154
159
  getFocusableChildren(element, options) {
160
+ if (!element) {
161
+ return [];
162
+ }
155
163
  let elements = Array.prototype.slice.call(element.querySelectorAll(SKY_TABBABLE_SELECTOR));
156
164
  // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.
157
165
  if (!options || !options.ignoreTabIndex) {