|
| 1 | +# PatternFly Element | Jump links element |
| 2 | + |
| 3 | + |
| 4 | +## Usage |
| 5 | +This component is focused on reading content inside the <pfe-jump-links-panel> and updating a sidebar or horizontal nav with 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 nav, or have the nav build a DOM tree for you. Please note the shape of the DOM tree below. In order to support sub-section highlighting jump links must be very opinionated about the DOM tree. |
| 6 | + |
| 7 | +Inside of <pfe-jump-links-panel> add the class .pfe-jump-links-panel__section to tell the component to watch for when that section crosses the scroll threshold. If this section has sub-sections you 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 will match to the href attribute of the corresponding <a> tag. |
| 8 | + |
| 9 | +## Wiring up the nav |
| 10 | +The panel and nav are wired up by a scrolltarget and id. On the panel add an attribute scrolltarget="foo". This will correspond to the nav's #id. Add the corresponding id to your nav like so id="foo". The last step is to match the <a> tag's href attribute to specific sections (just like we would with same page anchor links). See below for a simple example with three sections where section two has two sub-sections: |
| 11 | + |
| 12 | +```html |
| 13 | +<pfe-jump-links-nav id="jumplinks1" default> |
| 14 | + <h4 slot="pfe-jump-links-nav--heading">Jump to section</h4> |
| 15 | + <ul> |
| 16 | + <li> |
| 17 | + <a href="#section1">Section 1</a> |
| 18 | + </li> |
| 19 | + <li> |
| 20 | + <a href="#section2">Section 2</a> |
| 21 | + <ul> |
| 22 | + <li> |
| 23 | + <a href="#section2.1">Section 2.1</a> |
| 24 | + </li> |
| 25 | + <li> |
| 26 | + <a href="#section2.2">Section 2.2</a> |
| 27 | + </li> |
| 28 | + </ul> |
| 29 | + </li> |
| 30 | + <li> |
| 31 | + <a href="#section3">Section 3</a> |
| 32 | + </li> |
| 33 | + </ul> |
| 34 | +</pfe-jump-links-nav> |
| 35 | +... |
| 36 | +<pfe-jump-links-panel> |
| 37 | + <h2 class="pfe-jump-links-panel__section" id="section1">Section 1</h2> |
| 38 | + <p>Some content...</p> |
| 39 | + <h2 class="pfe-jump-links-panel__section has-sub-section" id="section2">Section 2</h2> |
| 40 | + <p>Some content...</p> |
| 41 | + <h2 class="pfe-jump-links-panel__section sub-section" id="section2">Section 2.1</h2> |
| 42 | + <p>Some content...</p> |
| 43 | + <h2 class="pfe-jump-links-panel__section sub-section" id="section2">Section 2.2</h2> |
| 44 | + <p>Some content...</p> |
| 45 | + <h2 class="pfe-jump-links-panel__section" id="section2">Section 2</h2> |
| 46 | + <p>Some content...</p> |
| 47 | +</pfe-jump-links-panel> |
| 48 | +``` |
| 49 | + |
| 50 | +### Accessibility |
| 51 | +The template and DOM structure of this component are as follows: |
| 52 | +```html |
| 53 | +<nav> |
| 54 | + <h2 hidden>Page navigation</h2> // this is visually hidden |
| 55 | + <h4>Slotted content</h4> |
| 56 | + <ul> |
| 57 | + <li><a>Regular list item</a></li> |
| 58 | + <li><a>List item with sub sections</a></li> |
| 59 | + <li> |
| 60 | + <ul> |
| 61 | + <li><a>Nested sub section</a></li> |
| 62 | + </ul> |
| 63 | + </li> |
| 64 | + </ul> |
| 65 | +</nav> |
| 66 | +``` |
| 67 | + |
| 68 | +No extra roles or aria labels are required because we're using standard html tags in their prescribed uses. |
| 69 | + |
| 70 | +## Slots |
| 71 | + |
| 72 | +- `namedSlot`: The only slot this component has is the heading. The rest of the component works by creating a mirror shadowRoot based on the Light DOM markup. |
| 73 | + |
| 74 | +## Attributes |
| 75 | + |
| 76 | +- `attr`: autobuild Flips the switch on the component to create its own markup for the navigation. If you use this attribute, then no experience is given for non-JS runtimes and the component will crawl the associated panel to come up with its own list of links. |
| 77 | + |
| 78 | +## Events |
| 79 | +This component fires an event when a link is made active. |
| 80 | + |
| 81 | + |
| 82 | +## Dependencies |
| 83 | +Describe any dependent elements or libraries here too. |
| 84 | + |
| 85 | +## Dev |
| 86 | + |
| 87 | + `npm start` |
| 88 | + |
| 89 | +## Test |
| 90 | + |
| 91 | + `npm run test` |
| 92 | + |
| 93 | +## Build |
| 94 | + |
| 95 | + `npm run build` |
| 96 | + |
| 97 | +## Demo |
| 98 | + |
| 99 | +From the PFElements root directory, run: |
| 100 | + |
| 101 | + `npm run demo` |
| 102 | + |
| 103 | +## Code style |
| 104 | + |
| 105 | +Jump links (and all PFElements) use [Prettier][prettier] to auto-format JS and JSON. The style rules get applied when you commit a change. If you choose to, you can [integrate your editor][prettier-ed] with Prettier to have the style rules applied on every save. |
| 106 | + |
| 107 | +[prettier]: https://github.com/prettier/prettier/ |
| 108 | +[prettier-ed]: https://prettier.io/docs/en/editors.html |
| 109 | +[web-component-tester]: https://github.com/Polymer/web-component-tester |
0 commit comments