Skip to content

Commit af4bc70

Browse files
fix: Jump links styles and browser fixes (#1652)
* fix: Update jump links assets * fix: Update docs * fix: Revert doc updates * fix: Minor updates * fix: Bringing in bug fixes from openshift * fix: WOrking through issues * fix: Working through issue with decomment on more complex templates * fix: Working through horizontal nav styles; moving functionality into jump links nav * fix: Working through jump links state * fix: Update package-lock * fix: Push rendering logic into template * fix: Resolved horizontal/mobile rendering * fix: Working through stickiness * fix: Working through the stack of sticky elements * fix: Working through stacking * fix: Incorporate pf variables * fix: Update formatting in sass files * fix: Add a global instances registry for each component * fix: Move find polyfill to pfelement * fix: Note if an element is visible * fix: Working through state * fix: Working through scroll events * fix: Set git status * fix: Remove scroll handler for temporary one while smooth scrolling * fix: Tidying up comments * fix: Resolve conflict between multiple jump links on a page * fix: Update mobile experience * fix: Remove todo note * fix: Added TODO notes from demo * fix: Correcting the scroll offset by fixing the sticky state * fix: Remove unneeded comments * fix: Add panel change event to events object * fix: Fix bug in autobuilder and add comments to JS * fix: Adjust scrollTo if navigation element is stuck * fix: Adding docs to functions; add change event to setters for panel and sections * fix: Cleaning up padding and alignment * fix: Add a few todo notes * fix: Add jsdoc to pfe-jump-links * fix: Revert gulp updates * fix: Updating README * fix: Update dependencies * fix: Fixing the calculations * fix: Remove unused code from panel * fix: Account for the use of the spacers in the panel * fix: Update changelo * fix: Update tests to fix errors; still need to add more tests later * fix: Jump links brings accordion now so no need to list it twice * fix: Fussing with styles for Firefox * fix: Resolve bad filter on NodeList * fix: Wrap horizontal styles in media query * fix: Update to use scope instead of children * fix: Pull out loop into separate method * fix: Account for height of accordion header on mobile * feat: Adding todo notes and setting stuck value after scrolling * fix: Accounting for accordions that aren't sticky yet * Update elements/pfe-jump-links/src/pfe-jump-links-nav.js Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8d41fc7 commit af4bc70

32 files changed

+2396
-1762
lines changed

CHANGELOG-1.x.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# 1.x.x (TBD)
1+
# 1.10.0 (2021-07-08)
22

3-
- [](https://github.com/patternfly/patternfly-elements/commit/) chore: Minor testing updates
3+
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: Jump links navigation rework to support panel customizations and elements in separate DOMs; horizontal designs aligned to kit
44

55
# 1.9.3 (2021-06-16)
66

docs/main.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:root {
22
--pfe-theme--font-family: "Red Hat Text", "Overpass", Helvetica, Arial, sans-serif;
33
--pfe-theme--font-family--heading: "Red Hat Display", "Overpass", Helvetica, Arial, sans-serif;
4+
--pfe-navigation--Height--actual: 60px;
45
}
56

67
html,
@@ -110,6 +111,7 @@ main.basic {
110111
}
111112

112113
.logo-bar {
114+
--pfe-navigation--Height--actual: 60px;
113115
position: fixed;
114116
top: 0;
115117
left: 0;

elements/pfe-accordion/demo/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
<script>
3131
require([
32-
'../dist/pfe-accordion.umd.js',
3332
'../../pfe-band/dist/pfe-band.umd.js',
3433
'../../pfe-card/dist/pfe-card.umd.js',
3534
'../../pfe-cta/dist/pfe-cta.umd.js',

elements/pfe-accordion/src/pfe-accordion-header.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,23 @@ class PfeAccordionHeader extends PFElement {
118118
if (this.firstElementChild && this.firstElementChild.tagName) {
119119
// If the first element is a slot, query for it's content
120120
if (this.firstElementChild.tagName === "SLOT") {
121-
const slotted = this.firstElementChild.assignedNodes();
121+
// Get the assigned node(s) for the slot
122+
let slotted = this.firstElementChild.assignedNodes();
123+
124+
// Check for default slot content if no nodes assigned
125+
if (slotted.length === 0) {
126+
slotted = [...this.firstElementChild.children];
127+
}
128+
122129
// If there is no content inside the slot, return empty with a warning
123130
if (slotted.length === 0) {
124131
this.warn(`No heading information exists within this slot.`);
125132
return;
126133
}
134+
127135
// If there is more than 1 element in the slot, capture the first h-tag
128136
if (slotted.length > 1) this.warn(`Heading currently only supports 1 tag.`);
137+
129138
const htags = slotted.filter((slot) => slot.tagName.match(/^H[1-6]/) || slot.tagName === "P");
130139
if (htags.length > 0) {
131140
// Return the first htag and attach an observer event to watch for it

elements/pfe-jump-links/README.md

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
# PatternFly Element | Jump links element
22

3-
43
## Usage
5-
This component watches the content inside a `<pfe-jump-links-panel>` and updates the corresponding `<pfe-jump-links-nav>` to indicate the section of the document currently being viewed. As a developer, you have the choice of whether you bring your own markup to the navigation element or have it build for you (see `autobuild` attribute below). Please note the shape of the markup that is required. In order to support sub-section highlighting, jump links must be somewhat opinionated about the DOM tree.
4+
This component watches the content inside a panel and updates the connected `<pfe-jump-links-nav>` to indicate the section of the document currently being viewed. As a developer, you have the choice of whether you bring your own markup to the navigation or have it build for you (see `autobuild` attribute below). Please note the shape of the markup that is required. In order to support sub-section highlighting, jump links must be somewhat opinionated about the DOM tree.
5+
6+
Inside the panel, every section must have at least an `id` present. If using autobuild, the `id` needs to be present on the tag containing the label text or make use of the `nav-label` attribute to manually define the label. The `nav-label` attribute will always take precedence over the text content. For faster processing, include the class `.pfe-jump-links-panel__section` to any elements you want the navigation to watch. Each item meeting these requirements inside a panel are called sections.
7+
8+
When each section crosses the scroll threshold, the navigation will highlight to show it is active. If it has sub-sections, the nested children will become visible.
9+
10+
If you are manually building the navigation, ensure that every section's id is reflected in the href attribute of the corresponding `<a>` tag (see below).
11+
12+
## Wiring up jump links
13+
14+
There are a few approaches to connecting a navigation element to a panel.
15+
16+
Panels can be:
617

7-
Inside the `<pfe-jump-links-panel>` add the class `.pfe-jump-links-panel__section` to any elements you want the navigation to watch; when that element crosses the scroll threshold, the navigation will highlight to show it is active. If it has sub-sections, add the class `.has-sub-section` to the section parent (i.e. section 8) and add `.sub-section` to the child sections (i.e. 8.1). Make sure to add an id to each section, this id should match to the href attribute of the corresponding `<a>` tag (see below).
18+
1. `pfe-jump-links-panel` elements with a `scrolltarget` attribute equal to the `id`
19+
2. Any element with a `scrolltarget` attribute equal to the `id` of the `pfe-jump-links-nav`.
20+
3. Defined using the panel setter
821

9-
## Wiring up the nav
22+
For routes 1 and 2 above:
1023

11-
The panel and nav are connected via a scrolltarget and id. On the panel, add an attribute `scrolltarget="foo"`. This will correspond to the `pfe-jump-links-nav` on the page with `id="foo"`. The last step is to match the `<a>` tag's href attribute to specific sections (just like you would with same page anchor links). See below for a simple example with three sections where section two has two sub-sections:
24+
The panel and navigation are connected via a scrolltarget and id. On the panel, add an attribute `scrolltarget="foo"`. This will correspond to the `pfe-jump-links-nav` on the page with `id="foo"`. If you are manually constructing the navigation, the last step is to match the `<a>` tags' href attribute to specific sections (just like you would with anchor links). See below for an example:
1225

1326
```html
14-
<pfe-jump-links-nav id="jumplinks1" default>
15-
<h4 slot="pfe-jump-links-nav--heading">Jump to section</h4>
27+
<pfe-jump-links-nav id="jumplinks1">
28+
<h4 slot="heading">Jump to section</h4>
1629
<ul>
1730
<li>
1831
<a href="#section1">Section 1</a>
@@ -33,29 +46,55 @@ The panel and nav are connected via a scrolltarget and id. On the panel, add an
3346
</li>
3447
</ul>
3548
</pfe-jump-links-nav>
36-
...
49+
<!-- For approach #2 above, pfe-jump-links-panel could be substituted for a `div` -->
3750
<pfe-jump-links-panel scrolltarget="jumplinks1">
3851
<h2 class="pfe-jump-links-panel__section" id="section1">Section 1</h2>
3952
<p>Some content...</p>
40-
<h2 class="pfe-jump-links-panel__section has-sub-section" id="section2">Section 2</h2>
53+
<h2 class="pfe-jump-links-panel__section" id="section2">Section 2</h2>
4154
<p>Some content...</p>
42-
<h2 class="pfe-jump-links-panel__section sub-section" id="section2">Section 2.1</h2>
55+
<h2 class="pfe-jump-links-panel__section" id="section2">Section 2.1</h2>
4356
<p>Some content...</p>
44-
<h2 class="pfe-jump-links-panel__section sub-section" id="section2">Section 2.2</h2>
57+
<h2 class="pfe-jump-links-panel__section" id="section2">Section 2.2</h2>
4558
<p>Some content...</p>
46-
<h2 class="pfe-jump-links-panel__section" id="section2">Section 2</h2>
59+
<h2 class="pfe-jump-links-panel__section" id="section3">Section 3</h2>
4760
<p>Some content...</p>
4861
</pfe-jump-links-panel>
4962
```
5063

64+
Using the panel setter requires capturing the `pfe-jump-links-nav` element from the document and setting it's `panel` property equal to the NodeItem you want to use.
65+
66+
```html
67+
<pfe-jump-links-nav id="jumplinks2" autobuild></pfe-jump-links-nav>
68+
<div id="jumplinks-panel">...</div>
69+
```
70+
71+
After ensuring the `pfe-jump-links-nav` element is defined, set the panel to point to the appropriate Node in your document.
72+
73+
```js
74+
Promise.all([customElements.whenDefined("pfe-jump-links-nav")]).then(() => {
75+
const nav = document.getElementById("jumplinks2");
76+
const panel = document.getElementById("jumplinks-panel");
77+
if (nav && panel) nav.panel = panel;
78+
});
79+
```
80+
81+
Alternatively, you can manually define your sections (rather than their containing panel) by passing a NodeList to the sections setter. If you define the sections manually, you do _not_ need to define their panel.
82+
83+
```js
84+
Promise.all([customElements.whenDefined("pfe-jump-links-nav")]).then(() => {
85+
const nav = document.getElementById("jumplinks2");
86+
const sections = document.querySelectorAll(".custom-section-identifier");
87+
if (nav && sections && sections.length > 0) nav.sections = sections;
88+
});
89+
```
90+
5191
### Accessibility
5292

53-
The template and DOM structure of this component are as follows:
93+
The template inside the component are roughly as follows:
5494

5595
```html
5696
<nav>
57-
<h2 hidden>Page navigation</h2> // this is visually hidden
58-
<h4>Slotted content</h4>
97+
<h4>Slotted heading (describes function)</h4>
5998
<ul>
6099
<li><a>Regular list item</a></li>
61100
<li><a>List item with sub sections</a></li>
@@ -68,21 +107,33 @@ The template and DOM structure of this component are as follows:
68107
</nav>
69108
```
70109

71-
No extra roles or aria labels are required because we're using standard html tags in their prescribed uses.
72-
73110
## Slots
74111

112+
- `heading`: This slot is for the navigation element, `pfe-jump-links-nav` to identify the markup for the list's heading.
75113

76-
- `pfe-jump-links-nav--heading`: This slot is for the navigation element, `pfe-jump-links-nav` to identify the markup for the list's heading.
114+
### Available slots but not currently rendered
115+
<!-- @TODO We need designs for what to do with the information in these slots -->
116+
- `cta`: This slot is for the call-to-action for `pfe-jump-links-nav` to identify the markup for the call-to-action element.
117+
- `logo`: This slot is for the navigation element, `pfe-jump-links-nav` to identify the markup for the navigation logo.
77118

78-
The rest of the component works by creating a mirror shadowRoot based on the Light DOM markup.
119+
The rest of the component works by creating a mirror shadowRoot based on the provided light DOM markup or, if using autobuild, it generates the mark-up based on the identified sections.
79120

80121

81122
## Attributes
82123

83-
- `autobuild`: Flips the switch on the component to create its own markup for the navigation. You can add `pfe-jump-links-panel__section` to each section that should show in the nav. If you want to use sub-sections add `has-sub-section` to the parent section that should always show and the `sub-section` class to the children of that section. If you use this attribute, keep in mind that non-JavaScript environments (some search engines, browsers with JS disabled) will not see the proper markup.
124+
### `pfe-jump-links-nav`
125+
126+
- `autobuild`: Creates its own markup for the navigation based on the defined sections.
127+
128+
- `horizontal`: Switches rendering of the jump links from vertical to a horizontal, secondary navigation style.
129+
130+
- `sr-text`: This attribute is read when the component upgrades to provide the innerText of the heading. If there is no `sr-text` attribute then the component defaults to "Jump to section". This attribute is to enable translations.
131+
132+
- `color`: Currently there are 2 options for the background color of the component; lightest or darkest.
133+
134+
- `offset`: This attribute determines the distance from the top of the browser window where the `pfe-jump-links-nav` should be attached. For instance `offset="600"` would mean that the component attaches at 600px from the top of the viewport. If this variable has not been set, it calculates the height of the pfe-navigation plus any sticky horizontal navigation
84135

85-
- `sr-text`: This attribute is read when the component upgrades to provide the innerText of the heading. If there is no `sr-text` attribute then the component defaults to "Jump to section". This attribute is to enable translations and internationalization.
136+
### `pfe-jump-links-panel`
86137

87138
- `offset`: This attribute determines the distance from the top of the browser window to trigger a switch from one link being active to the next. For instance `offset="600"` would mean that threshold flips at 600px from the top. The default is set at 200, and if you desire 200px then you can leave this attribute off. The `offset` attribute should be placed on `pfe-jump-links-panel`. There is a css solution to control the offset, however the attribute value takes precedence over css. To read more about a css solution see below.
88139

elements/pfe-jump-links/demo/demo.css

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ html {
33
scroll-behavior: smooth;
44
}
55

6-
#nav-vars-set {
7-
--pfe-navigation--Height--actual: 55px;
8-
--pfe-jump-links--nav-height: 62px;
9-
--pfe-jump-links-panel__section--spacer: 117px;
10-
--pfe-jump-links-panel--offset: 55px;
6+
/* #nav-vars-set { */
7+
/* --pfe-navigation--Height--actual: 55px; */
8+
/* --pfe-jump-links--nav-height: 62px; */
9+
/* --pfe-jump-links-panel__section--spacer: 117px;
10+
--pfe-jump-links-panel--offset: 55px; */
1111

1212
/* For testing */
1313
/* --pfe-jump-links-panel--offset: 120px; */
1414
/* --pfe-jump-links-panel--offset: 20vw; */
1515
/* --pfe-jump-links-panel--offset: 80; */
16-
}
16+
/* } */
1717

1818
a.pfe-jump-links-nav__item {
1919
/* Just in here for sanity knowing outside styles can't leak in */
@@ -22,7 +22,25 @@ a.pfe-jump-links-nav__item {
2222

2323
.sticky {
2424
position: sticky;
25-
top: 55px;
25+
top: 0;
26+
z-index: 80;
27+
}
28+
29+
.sticky pfe-jump-links-nav {
30+
top: 0 !important;
31+
}
32+
33+
@media(min-width: 992px) {
34+
.sticky {
35+
top: 150px !important;
36+
}
37+
}
38+
39+
#jumplinks9 {
40+
--pfe-jump-links--offset: 60px;
41+
@media(min-width: 992px) {
42+
--pfe-jump-links--offset: 130px;
43+
}
2644
}
2745

2846

@@ -45,24 +63,25 @@ a.pfe-jump-links-nav__item {
4563

4664

4765
/* FAKE NAV BAR */
48-
#navbar {
66+
/* #navbar {
4967
position: fixed;
5068
top: 0;
5169
width: 100%;
5270
height: var(--pfe-navigation--Height--actual);
5371
z-index: 9;
5472
padding-top: 0;
55-
}
73+
} */
5674

57-
#navbar a {
75+
/* #navbar a {
5876
float: left;
5977
display: block;
6078
color: #f2f2f2;
6179
text-align: center;
6280
padding: 14px 16px;
6381
text-decoration: none;
6482
font-size: 17px;
65-
}
83+
} */
84+
6685
/*
6786
.pfe-jump-links__section--spacer {
6887
content: '';

0 commit comments

Comments
 (0)