Skip to content

Commit afd7d6e

Browse files
kylebuch8mwczchrisdo1starryeyez024
authored
fix: remove navigation report height for specific id (#746)
* feat(pfe-navigation): report pfe-nav's height in a global CSS variable * update changelog * change the height var to be more BEMy * set nav height variable to use px * fixed merge conflict * fixed variable name in readme * fixed typo in readme * fixed nav test to use correct variable name * set height custom property to use underscores only if region is declared. * added px value back into variable. * removed px string from custom height property to match clientHeight. * Updated nav readme, fixed typo and replaced ellipses with colon * removing logic for setting css variable for a nav with an id * removing attribute listener for id again * code revisions Co-authored-by: Michael Clayton <[email protected]> Co-authored-by: Chris Doherty <[email protected]> Co-authored-by: Kendall Totten <[email protected]>
1 parent 3fa441f commit afd7d6e

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

elements/pfe-navigation/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ All slots are optional and can be left off if not needed. Slots prefixed with `m
2121
```
2222
<a style="--pfe-navigation__logo--MinWidth: 160px" slot="logo" href="https://company.com"><img class="logo" src="https://via.placeholder.com/150x50.png" title="Company logo" /></a>
2323
```
24-
- `search`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders a dropdown in the navigation for the search functionality. Inside the tray for the slot, we recommend tagging the search form or search functionality that includes the input and submit button with the attribute `pfe-navigation--mobile-search`. The element inside the search slot that is tagged with this attribute will be copied into the mobile menu and appear above the accordion for the main navigation. Example:
24+
- `search`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders a dropdown in the navigation for the search functionality. Inside the tray for the slot, we recommend tagging the search form or search functionality that includes the input and submit button with the attribute `pfe-navigation--mobile-search`. The element inside the search slot that is tagged with this attribute will be copied into the mobile menu and appear above the accordion for the main navigation. Example:
2525
2626
```
2727
<pfe-navigation-item slot="search" pfe-icon="web-search">
2828
<h2 slot="trigger"><a href="#url-to-search-page">Search</a></h2>
2929
</pfe-navigation-item>
3030
```
31-
- `language`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders the dropdown for the user to select the site language. Example:
31+
- `language`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders the dropdown for the user to select the site language. Example:
3232
3333
```
3434
<pfe-navigation-item slot="language" pfe-icon="web-globe" slot="trigger">
@@ -40,7 +40,7 @@ All slots are optional and can be left off if not needed. Slots prefixed with `m
4040
```
4141
<a href="/url-to-language-page" slot="mobile-language" pfe-icon="web-globe" hidden>English</a>
4242
```
43-
- `login`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders the dropdown for the user to log into the site. Example:
43+
- `login`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders the dropdown for the user to log into the site. Example:
4444
4545
```
4646
<pfe-navigation-item slot="login" pfe-icon="web-user">
@@ -51,7 +51,7 @@ All slots are optional and can be left off if not needed. Slots prefixed with `m
5151
```
5252
<a href="/login" slot="mobile-login" pfe-icon="web-user" hidden>Login/Register</a>
5353
```
54-
- `site-switcher`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders the dropdown for the site switcher, allowing the user to navigate an ecosystem of websites. Example:
54+
- `site-switcher`: This slot can accept any html mark-up, however the `pfe-navigation-item` is recommended. When assigned to a navigation-item component, this slot renders the dropdown for the site switcher, allowing the user to navigate an ecosystem of websites. Example:
5555
5656
```
5757
<pfe-navigation-item slot="site-switcher" pfe-icon="web-grid-3x3">
@@ -68,8 +68,7 @@ All slots are optional and can be left off if not needed. Slots prefixed with `m
6868
6969
### CSS Variables
7070
71-
- `--pfe-navigation--Height--actual`: when pfe-navigation initializes, it will create a global (on `body`) CSS variable that contains the height of the pfe-navigation item. The primary uses for this is calculating the offset for anchor links, and for positioning a sticky sub-header below the pfe-navigation. Note that multiple pfe-navigation elements will write the same variable, unless:
72-
- `--pfe-navigation__${ID}--Height--actual`: like the previous variable, but if the pfe-navigation has an `id` attribute, it will be appended to the CSS variable name. This makes it possible to distinguish the heights of multiple pfe-navigation elements on the same page.
71+
- `--pfe-navigation--Height--actual`: When `pfe-navigation` initializes, it will create a global (on `body`) CSS variable that contains the height of the `pfe-navigation` element. Possible uses include calculating the offset for anchor links or positioning a sticky sub-header below the `pfe-navigation`. Note that multiple `pfe-navigation` elements will write the same variable.
7372
7473
---
7574

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PfeNavigation extends PFElement {
5555
}
5656

5757
static get observedAttributes() {
58-
return ["pfe-full-width", "id"];
58+
return ["pfe-full-width"];
5959
}
6060

6161
constructor() {
@@ -165,15 +165,6 @@ class PfeNavigation extends PFElement {
165165
this._observer.disconnect();
166166
}
167167

168-
attributeChangedCallback(name, oldValue, newValue) {
169-
super.attributeChangedCallback(name, oldValue, newValue);
170-
switch (name) {
171-
case "id":
172-
this._reportHeight();
173-
break;
174-
}
175-
}
176-
177168
_resizeHandler(event) {
178169
// Set the visibility of items
179170
this._setVisibility(this.offsetWidth);
@@ -379,16 +370,9 @@ class PfeNavigation extends PFElement {
379370
* Used to position sticky subnavigation items under this.
380371
*
381372
* The name of the global CSS variable is `--pfe-navigation--Height--actual`.
382-
* If this nav has an `id` attribute, the id will be appended to the variable
383-
* name to distinguish it from other pfe-navigation items on the page
384-
* (unlikely, but imagine a demo page with 20 example pfe-navigation elements
385-
* in different states, and one genuine pfe-navigation element at the top
386-
* used for actual navigation).
387373
*/
388374
_reportHeight() {
389-
const cssVarName = `--pfe-navigation${
390-
this.id ? `__${this.id}--` : "--"
391-
}Height--actual`;
375+
const cssVarName = `--${this.tag}--Height--actual`;
392376
const height = this.clientHeight + "px";
393377
document.body.style.setProperty(cssVarName, height);
394378
}

elements/pfe-navigation/test/pfe-navigation_test.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,6 @@ <h3 slot="trigger"><a href="#">Products</a></h3>
612612
// check the exact height (race condition over which writes its var
613613
// last). Just check that the var was created.
614614
assert.isDefined(reportedHeight, "pfe-navigation without id reports height to default css variable");
615-
616-
// should also create a namespaced var if the nav has an ID
617-
pfeNavigation.setAttribute("id", "ABCDEFG");
618-
619-
const reportedHeightNamespaced = document.body.style.getPropertyValue("--pfe-navigation__ABCDEFG--Height--actual").replace("px", "");
620-
621-
assert.isDefined(reportedHeightNamespaced, "pfe-navigation with id reports height to namespaced css variable");
622-
assert.equal(pfeNavigation.clientHeight.toString(), reportedHeightNamespaced, "pfe-navigation with id reports the correct height");
623615
});
624616
});
625617

0 commit comments

Comments
 (0)