-
Notifications
You must be signed in to change notification settings - Fork 106
feat(pfe-navigation): report pfe-nav's height in a global CSS variable #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Great idea! Hmm how about |
Sounds good to me! Change made.
I think it's better to use the ID, or a new attribute ( top: var(--pfe-navigation--2--Height--actual)would break if the ordering changes or navs are added/removed, but this is resilient: top: var(--pfe-navigation--main-menu--Height--actual)
No, I didn't consider that scenario. Is that the right thing to do? Might it be better to set it to 0 any time the nav isn't sticky? |
|
@mwcz Instead of WIP, going forward could you open a draft PR? https://github.blog/2019-02-14-introducing-draft-pull-requests/ |
|
Since the ID represents a region, I think it should be underscore prefixed instead: |
castastrophe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to determine functionality when the navigation is not sticky.
elements/pfe-navigation/README.md
Outdated
| ### CSS Variables | ||
| - `--pfe-navigation--ReportedHeight`: 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... | ||
| - `--pfe-navigation--ReportedHeight-${ID}`: like the previous varaible, 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - `--pfe-navigation--ReportedHeight-${ID}`: like the previous varaible, 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. | |
| - `--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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@castastrophe updated lines 72 and 73 to show the correct variable name.
| */ | ||
| _reportHeight() { | ||
| const cssVarName = | ||
| `--pfe-navigation--${this.id ? `${this.id}--` : ""}Height--actual`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `--pfe-navigation--${this.id ? `${this.id}--` : ""}Height--actual`; | |
| `--pfe-navigation__${this.id ? `${this.id}--` : ""}Height--actual`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@castastrophe replaced -- with __
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@castastrophe @mwcz looking at this again, if there is no ID, the resulting custom property will look like this:
--pfe-navigation__Height--actual
Is that correct or should it be --pfe-navigation--Height--actual in which case we'd need to move the __ into the ternary?
|
When there is a main navigation and a secondary (horizontal) navigation on a page, I think there are two mutually exclusive ways that you would want them to interact:
In my mind, this PR is intended to help solve for use case #1, therefore the value of the main-menu-offset variable can remain constant. |
kylebuch8
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limitless Guitarist: Tom Morello
What has changed and why
pfe-navigation will now create a global CSS variable containing the pfe-navigation element's height. @chrisdo1 requested this so that a sticky sub-nav can be correctly positioned below the pfe-navigation element. The height can also be used to calculate a vertical offset for anchor links on pages where pfe-navigation is sticky.
--pfe-navigation--ReportedHeight: when pfe-navigation initializes, it will create a global (onbody) 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...--pfe-navigation--ReportedHeight-${ID}: like the previous varaible, but if the pfe-navigation has anidattribute, 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.@castastrophe, what do you think of these variable names? I don't think they're proper BEM because ReportedHeight isn't a property. I didn't want to use "Height" beccause I want it to be clear that this is a read-only property, and that overridding it will have no effect.
Testing instructions
Automated tests are included in the PR. You can also;
Ready-for-merge Checklist