-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add JS to skip links to focus on content
- Loading branch information
Showing
10 changed files
with
120 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,6 @@ module.exports = { | |
return config; | ||
}, | ||
docs: { | ||
autodocs: false, | ||
autodocs: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export class SkipLink { | ||
linkedElementListener = false; | ||
|
||
constructor($module) { | ||
this.$module = $module; | ||
this.linkedElementId = $module.getAttribute("href").split("#").pop(); | ||
this.$linkedElement = | ||
$module && | ||
this.linkedElementId && | ||
document.getElementById(this.linkedElementId); | ||
} | ||
|
||
init() { | ||
if (!this.$module || !this.$linkedElement) { | ||
return; | ||
} | ||
this.$module.addEventListener("click", () => this.focusLinkedElement()); | ||
} | ||
|
||
focusLinkedElement() { | ||
if (!this.$linkedElement.getAttribute("tabindex")) { | ||
this.$linkedElement.setAttribute("tabindex", "-1"); | ||
this.$linkedElement.classList.add("tna-!--no-focus-style"); | ||
|
||
if (!this.linkedElementListener) { | ||
this.$linkedElement.addEventListener("blur", () => | ||
this.removeFocusProperties(), | ||
); | ||
this.linkedElementListener = true; | ||
} | ||
} | ||
|
||
this.$linkedElement.focus(); | ||
} | ||
|
||
removeFocusProperties() { | ||
this.$linkedElement.removeAttribute("tabindex"); | ||
this.$linkedElement.classList.remove("tna-!--no-focus-style"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{%- set containerClasses = [params.classes] if params.classes else [] -%} | ||
<a href="#{{ params.href if params.href else 'main-content' }}" class="tna-skip-link {{ containerClasses | join(' ') }}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}> | ||
<a href="#{{ params.href if params.href else 'main-content' }}" class="tna-skip-link {{ containerClasses | join(' ') }}" data-module="tna-skip-link" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}> | ||
{{ params.text if params.text else 'Skip to main content' }} | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters