Skip to content

Commit 6a41811

Browse files
mwczcastastrophe
andcommitted
fix reference error in pfe-navigation when slot is missing (#695)
* fix reference error when search slot is missing * run prettier on nav, somehow it was missed * update changelog * Update CHANGELOG-prerelease.md Co-Authored-By: [ Cassondra ] <[email protected]> Co-authored-by: [ Cassondra ] <[email protected]>
1 parent 21fe2d7 commit 6a41811

File tree

2 files changed

+69
-24
lines changed

2 files changed

+69
-24
lines changed

CHANGELOG-prerelease.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Prerelease 37 ( TBD )
2+
3+
Tag: [v1.0.0-prerelease.37](https://github.com/patternfly/patternfly-elements/releases/tag/v1.0.0-prerelease.37)
4+
5+
- [27aa87d3](https://github.com/patternfly/patternfly-elements/commit/082467) fix: reference error when slot is missing in pfe-navigation
6+
17
## Prerelease 36 ( 2020-01-20 )
28

39
Tag: [v1.0.0-prerelease.36](https://github.com/patternfly/patternfly-elements/releases/tag/v1.0.0-prerelease.36)

elements/pfe-navigation/src/pfe-navigation.js

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ class PfeNavigation extends PFElement {
6666
// Capture shadow elements
6767
this._overlay = this.shadowRoot.querySelector(`.${this.tag}__overlay`);
6868
this._wrapper = this.shadowRoot.querySelector(`.${this.tag}__wrapper`);
69-
this._menuItem = this.shadowRoot.querySelector(`${PfeNavigationItem.tag}[pfe-icon="web-mobile-menu"]`);
69+
this._menuItem = this.shadowRoot.querySelector(
70+
`${PfeNavigationItem.tag}[pfe-icon="web-mobile-menu"]`
71+
);
7072

7173
this._slots = {
72-
language: this.shadowRoot.querySelector(`${PfeNavigationItem.tag}[pfe-icon="web-user"]`),
73-
login: this.shadowRoot.querySelector(`${PfeNavigationItem.tag}[pfe-icon="web-globe"]`)
74+
language: this.shadowRoot.querySelector(
75+
`${PfeNavigationItem.tag}[pfe-icon="web-user"]`
76+
),
77+
login: this.shadowRoot.querySelector(
78+
`${PfeNavigationItem.tag}[pfe-icon="web-globe"]`
79+
)
7480
};
7581

7682
// Initialize active navigation item to empty array
@@ -79,7 +85,9 @@ class PfeNavigation extends PFElement {
7985

8086
// make sure we close all of the nav items and hide the overlay when
8187
// the mobile menu button is closed
82-
this._menuItem.shadowRoot.querySelector(".pfe-navigation-item__trigger").addEventListener("click", this._menuItemClickHandler);
88+
this._menuItem.shadowRoot
89+
.querySelector(".pfe-navigation-item__trigger")
90+
.addEventListener("click", this._menuItemClickHandler);
8391

8492
// make sure we close all of the nav items and hide the overlay
8593
// when it's clicked
@@ -98,7 +106,7 @@ class PfeNavigation extends PFElement {
98106
// If only one value exists in the array, it starts at that size and goes up
99107
this.breakpoints = {
100108
main: [0, 1023], // visible from 0 - 1200px
101-
search: [640], // visible from 768px +
109+
search: [640], // visible from 768px +
102110
"mobile-search": [0, 639],
103111
language: [640],
104112
"mobile-language": [0, 639],
@@ -112,7 +120,9 @@ class PfeNavigation extends PFElement {
112120
// Watch for screen resizing
113121
window.addEventListener("resize", this._resizeHandler);
114122
} else {
115-
console.error("This component does not have any light DOM children. Please check documentation for requirements.");
123+
console.error(
124+
"This component does not have any light DOM children. Please check documentation for requirements."
125+
);
116126
}
117127

118128
this._observer.observe(this, { childList: true });
@@ -123,15 +133,23 @@ class PfeNavigation extends PFElement {
123133
// Remove the scroll, resize, and outside click event listeners
124134
window.removeEventListener("resize", this._resizeHandler);
125135

126-
if(this.hasAttribute("pfe-close-on-click") && this.getAttribute("pfe-close-on-click") === "external") {
136+
if (
137+
this.hasAttribute("pfe-close-on-click") &&
138+
this.getAttribute("pfe-close-on-click") === "external"
139+
) {
127140
document.removeEventListener("click", this._outsideListener);
128141
}
129142

130-
if(this.hasAttribute("pfe-sticky") && this.getAttribute("pfe-sticky") != "false") {
143+
if (
144+
this.hasAttribute("pfe-sticky") &&
145+
this.getAttribute("pfe-sticky") != "false"
146+
) {
131147
window.removeEventListener("scroll", this._stickyHandler);
132148
}
133149

134-
this._menuItem.shadowRoot.querySelector(".pfe-navigation-item__trigger").removeEventListener("click", this._menuItemClickHandler);
150+
this._menuItem.shadowRoot
151+
.querySelector(".pfe-navigation-item__trigger")
152+
.removeEventListener("click", this._menuItemClickHandler);
135153
this._overlay.removeEventListener("click", this._overlayClickHandler);
136154

137155
this._observer.disconnect();
@@ -146,11 +164,16 @@ class PfeNavigation extends PFElement {
146164
// If the item is open but not visible, update it to hidden
147165
if (item.expanded && !item.visible) {
148166
item.expanded = false;
149-
this._activeNavigationItems = this._activeNavigationItems.filter(i => i !== item);
167+
this._activeNavigationItems = this._activeNavigationItems.filter(
168+
i => i !== item
169+
);
150170
} else if (item.expanded && item.parent && item.parent.visible) {
151171
// if the parent is the mobile menu item and the size of the window is within
152172
// the main breakpoint, make sure that the mobile menu is expanded
153-
if (item.parent === this._menuItem && window.innerWidth <= this.breakpoints.main[1]) {
173+
if (
174+
item.parent === this._menuItem &&
175+
window.innerWidth <= this.breakpoints.main[1]
176+
) {
154177
item.parent.expanded = true; // Ensure the parent is open
155178
// If the parent item doesn't exist in the active array, add it
156179
if (!this._activeNavigationItems.includes(item.parent)) {
@@ -164,7 +187,7 @@ class PfeNavigation extends PFElement {
164187
}
165188

166189
_stickyHandler() {
167-
if(window.pageYOffset >= this.top) {
190+
if (window.pageYOffset >= this.top) {
168191
this.classList.add("pfe-sticky");
169192
} else {
170193
this.classList.remove("pfe-sticky");
@@ -176,7 +199,9 @@ class PfeNavigation extends PFElement {
176199
let isSelf = event.target === this;
177200
// Check if the clicked element contains or is contained by the navigation element
178201
let isChild = event.target.closest("pfe-navigation");
179-
let insideWrapper = event.target.tagName.includes("-") ? event.target.shadowRoot.querySelector("pfe-navigation") : null;
202+
let insideWrapper = event.target.tagName.includes("-")
203+
? event.target.shadowRoot.querySelector("pfe-navigation")
204+
: null;
180205

181206
// Check states to determine if the navigation items should close
182207
if (!isSelf && !(isChild || insideWrapper)) {
@@ -192,13 +217,17 @@ class PfeNavigation extends PFElement {
192217
let isVisible = false;
193218

194219
// If the slot exists, set attribute based on supported breakpoints
195-
if (this.slots[label] && this.slots[label].nodes.length > 0) {
220+
if (
221+
this.slots[label] &&
222+
this.slots[label].nodes &&
223+
this.slots[label].nodes.length > 0
224+
) {
196225
if (width >= start && (!end || (end && width <= end))) {
197226
isVisible = true;
198227
}
199228

200229
this.slots[label].nodes.forEach(node => {
201-
switch(label) {
230+
switch (label) {
202231
case "main":
203232
if (isVisible) {
204233
node.removeAttribute("show_content");
@@ -209,25 +238,29 @@ class PfeNavigation extends PFElement {
209238
this._menuItem.expanded = false;
210239
this._menuItem.tray.removeAttribute("hidden");
211240
// Remove menuItem from active items
212-
this._activeNavigationItems = this._activeNavigationItems.filter(item => item !== this._menuItem);
241+
this._activeNavigationItems = this._activeNavigationItems.filter(
242+
item => item !== this._menuItem
243+
);
213244
}
214245
node.navItems.forEach(item => {
215246
if (isVisible) {
216247
item.removeAttribute("parent_hidden");
217-
} else {
218-
item.setAttribute("parent_hidden", "");
219-
}
220-
});
248+
} else {
249+
item.setAttribute("parent_hidden", "");
250+
}
251+
});
221252
break;
222253
case (label.match(/^mobile/) || {}).input:
223254
if (isVisible) {
224255
// Set an attribute to show this region (strip the mobile prefix)
225256
this._menuItem.setAttribute(`show_${label.slice(7)}`, "");
226-
if (this._slots[label.slice(7)]) this._slots[label.slice(7)].removeAttribute("hidden");
257+
if (this._slots[label.slice(7)])
258+
this._slots[label.slice(7)].removeAttribute("hidden");
227259
node.removeAttribute("hidden");
228260
} else {
229261
this._menuItem.removeAttribute(`show_${label.slice(7)}`);
230-
if (this._slots[label.slice(7)]) this._slots[label.slice(7)].setAttribute("hidden", "");
262+
if (this._slots[label.slice(7)])
263+
this._slots[label.slice(7)].setAttribute("hidden", "");
231264
node.setAttribute("hidden", "");
232265
}
233266
break;
@@ -273,7 +306,10 @@ class PfeNavigation extends PFElement {
273306
this._setVisibility(this.offsetWidth);
274307

275308
// If the nav is set to sticky, inject the height of the nav to the next element in the DOM
276-
if(this.hasAttribute("pfe-sticky") && this.getAttribute("pfe-sticky") != "false") {
309+
if (
310+
this.hasAttribute("pfe-sticky") &&
311+
this.getAttribute("pfe-sticky") != "false"
312+
) {
277313
// Run the sticky check on first page load
278314
this._stickyHandler();
279315

@@ -282,7 +318,10 @@ class PfeNavigation extends PFElement {
282318
}
283319

284320
// Listen for clicks outside the navigation element
285-
if(this.hasAttribute("pfe-close-on-click") && this.getAttribute("pfe-close-on-click") === "external") {
321+
if (
322+
this.hasAttribute("pfe-close-on-click") &&
323+
this.getAttribute("pfe-close-on-click") === "external"
324+
) {
286325
document.addEventListener("click", this._outsideListener);
287326
}
288327

0 commit comments

Comments
 (0)