Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nice-baboons-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@patternfly/pfe-jump-links": patch
---

Applies aria-label to nav links (#1765)
2 changes: 1 addition & 1 deletion .github/workflows/visual-regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
}

- name: Add comment to PR
if: ${{ steps.format.outputs.comment }}
if: ${{ always() && steps.format.outputs.comment }}
id: comment
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
24 changes: 20 additions & 4 deletions elements/pfe-jump-links/pfe-jump-links-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ export class PfeJumpLinksNav extends LitElement {

private slots = new SlotController(this, 'heading', 'logo', 'cta');

/** Sets aria-labelledby on incoming ul and ol nodes */
private ariaMO = new MutationObserver(records => {
for (const record of records) {
for (const node of record.addedNodes) {
if (node instanceof HTMLOListElement || node instanceof HTMLUListElement) {
node.setAttribute('aria-labelledby', 'heading');
}
}
}
});

/**
* @requires {this.mobileBreakpoint || LitElement.breakpoint}
* @returns true if this is at or below the mobile breakpoint
Expand Down Expand Up @@ -431,9 +442,11 @@ export class PfeJumpLinksNav extends LitElement {
render() {
const content = html`
<nav part="nav">${this.isMobile ? '' : html`
<slot name="heading" class="pfe-jump-links-nav__heading" ?sr-only=${this.noHeader}>
<h3>${this.srText || 'Jump to section'}</h3>
</slot>`}${!this.horizontal ? '' : html`
<header id="heading">
<slot name="heading" class="pfe-jump-links-nav__heading" ?sr-only=${this.noHeader}>
<h3>${this.srText || 'Jump to section'}</h3>
</slot>
</header>`}${!this.horizontal ? '' : html`
<slot name="logo" class="pfe-jump-links-nav__logo"></slot>`}
<div id="container" part="content">${unsafeHTML(this.containerInnerHTML)}</div>${!this.horizontal ? '' : html`
<slot name="cta" class="pfe-jump-links-nav__cta"></slot>`}
Expand All @@ -442,7 +455,7 @@ export class PfeJumpLinksNav extends LitElement {

return !this.isMobile ? content : html`
<pfe-accordion>
<pfe-accordion-header>
<pfe-accordion-header id="heading">
<slot name="heading" class="pfe-jump-links-nav__heading">
<h3>${this.srText || 'Jump to section'}</h3>
</slot>
Expand All @@ -453,6 +466,9 @@ export class PfeJumpLinksNav extends LitElement {
}

firstUpdated() {
if (this.container) {
this.ariaMO.observe(this.container, { childList: true });
}
this._scrollHandler();
// Capture the updated UL tag
const menu = this.querySelector<HTMLElement>('ul, ol');
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<header class="logo-bar">
<button id="hamburger" aria-label="Expand Main Navigation">&#9776;</button>
<a href="/"><img src="/brand/logo/svg/pfe-icon-white-shaded.svg" alt="" />PatternFly Elements</a>
<a id="github-link" href="https://github.com/patternfly/patternfly-elements/tree/main/elements/pfe-accordion">
<a id="github-link" href="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/patternfly/patternfly-elements/">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512">
<title>GitHub</title>
<!-- Font Awesome Free 5.15.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) -->
Expand Down