@skyux/core 6.0.0-beta.8 → 6.0.0-beta.9

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.
@@ -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) {