-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add skipToContent function to SkipLinks.vue * Add test for function skipToContent * Refactor skip link functionality in SkipLinks unit test * Refactor SkipLinks component * move SkipLink to new structure * add space key handler * add data-testid & adjust tests --------- Co-authored-by: Odalys Adam <odalys.adam@dataport.de>
- Loading branch information
1 parent
cf23f24
commit 8ca6325
Showing
10 changed files
with
94 additions
and
74 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
import { createTestingI18n } from "@@/tests/test-utils/setup"; | ||
import { mount } from "@vue/test-utils"; | ||
import SkipLink from "./SkipLink.vue"; | ||
|
||
jest.mock("vue-router", () => ({ | ||
useRoute: () => ({ hash: "#" }), | ||
})); | ||
|
||
describe("@ui-skip-link", () => { | ||
const setup = () => { | ||
const wrapper = mount(SkipLink, { | ||
global: { | ||
plugins: [createTestingI18n()], | ||
}, | ||
}); | ||
|
||
return { wrapper }; | ||
}; | ||
|
||
it("should render its skip link", async () => { | ||
const { wrapper } = setup(); | ||
|
||
expect(wrapper.find("[data-testid=skip-link]").exists()).toBe(true); | ||
}); | ||
|
||
it("should skip to main content area", async () => { | ||
const { wrapper } = setup(); | ||
|
||
const mainContentElement = window.document.createElement("div"); | ||
mainContentElement.id = "main-content"; | ||
window.document.body.appendChild(mainContentElement); | ||
|
||
await wrapper.findComponent({ name: "SkipLink" }).trigger("keydown.enter"); | ||
|
||
expect(window.document.activeElement).toBe(mainContentElement); | ||
}); | ||
}); |
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,46 @@ | ||
<template> | ||
<a | ||
id="skip-link" | ||
tabindex="0" | ||
class="skip-link d-sr-only-focusable" | ||
href="#main-content" | ||
data-testid="skip-link" | ||
@keydown.enter.prevent="skipToMainContent" | ||
@keydown.space.prevent="skipToMainContent" | ||
> | ||
{{ $t("global.skipLink.mainContent") }} | ||
</a> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const programmaticFocus = (element: HTMLElement) => { | ||
element.setAttribute("tabindex", "-1"); | ||
element.focus(); | ||
setTimeout(() => element.removeAttribute("tabindex"), 1000); | ||
}; | ||
const skipToMainContent = () => { | ||
const mainContentElement = window.document.querySelector( | ||
"#main-content" | ||
) as HTMLElement; | ||
if (mainContentElement) { | ||
programmaticFocus(mainContentElement); | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.skip-link { | ||
position: absolute; | ||
top: 0px; | ||
left: 50%; | ||
padding: 0.5rem; | ||
color: rgba(var(--v-theme-primary)); | ||
background-color: white; | ||
border: 1px solid #555; | ||
border-radius: var(--radius-xs); | ||
transform: translate(-50%, 0); | ||
z-index: 1005; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import SkipLink from "./SkipLink.vue"; | ||
|
||
export { SkipLink }; |
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