Skip to content
Open
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
38 changes: 38 additions & 0 deletions packages/portal/src/components/generic/SkipLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<b-button
:class="classes"
data-qa="skip to content link"
@click="handleClick"
>
{{ $t(textPath) }}
</b-button>
</template>

<script>
export default {
name: 'SkipLink',

props: {
selector: {
type: String,
default: '#main'
},
classes: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this be changed?

type: String,
default: 'skip-main'
},
textPath: {
type: String,
default: 'layout.skipToMain'
}
},

methods: {
handleClick() {
const element = document.querySelector(this.selector);
element?.setAttribute('tabindex', '-1');
element?.focus();
}
}
};
</script>
20 changes: 8 additions & 12 deletions packages/portal/src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
ref="resetfocus"
data-qa="top page"
/>
<a
class="skip-main"
href="#main"
data-qa="main content accessibility link"
>
{{ $t('layout.skipToMain') }}
</a>
<SkipLink />
<PageHeader
ref="pageHeader"
/>
Expand Down Expand Up @@ -66,20 +60,22 @@
import useMakeToast from '@/composables/makeToast.js';
import versions from '../../pkg-versions';
import { activeFeatureNotification } from '@/features/notifications';
import SkipLink from '@/components/generic/SkipLink';

export default {
name: 'DefaultLayout',

components: {
DebugApiRequests: () => import('@/components/debug/DebugApiRequests'),
ClientOnly,
DebugApiRequests: () => import('@/components/debug/DebugApiRequests'),
ErrorModal,
NewFeatureNotification: () => import('@/components/generic/NewFeatureNotification'),
NotificationBanner: () => import('@/components/generic/NotificationBanner'),
PageCookiesWidget: () => import('@/components/page/PageCookiesWidget'),
PageHeader,
PageFooter: () => import('@/components/page/PageFooter'),
PageHeader,
ProvideCanonicalUrl,
NewFeatureNotification: () => import('@/components/generic/NewFeatureNotification'),
NotificationBanner: () => import('@/components/generic/NotificationBanner'),
ErrorModal
SkipLink
},

setup() {
Expand Down
12 changes: 4 additions & 8 deletions packages/portal/src/layouts/ds4ch.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<template>
<div class="ds4ch-layout">
<a
class="skip-main"
href="#main"
data-qa="main content accessibility link"
>
{{ $t('layout.skipToMain') }}
</a>
<SkipLink />
<DS4CHPageHeader
ref="pageHeader"
/>
Expand Down Expand Up @@ -35,6 +29,7 @@
import DS4CHPageHeader from '@/components/DS4CH/DS4CHPageHeader';
import DS4CHPageFooter from '@/components/DS4CH/DS4CHPageFooter';
import ProvideCanonicalUrl from '@/components/provide/ProvideCanonicalUrl';
import SkipLink from '@/components/generic/SkipLink';
import versions from '../../pkg-versions';

export default {
Expand All @@ -45,7 +40,8 @@
DS4CHPageHeader,
DS4CHPageFooter,
PageCookiesWidget: () => import('@/components/page/PageCookiesWidget'),
ProvideCanonicalUrl
ProvideCanonicalUrl,
SkipLink
},

head() {
Expand Down
12 changes: 4 additions & 8 deletions packages/portal/src/layouts/landing.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<template>
<div>
<a
class="skip-main"
href="#main"
data-qa="main content accessibility link"
>
{{ $t('layout.skipToMain') }}
</a>
<SkipLink />
<LandingPageHeader
ref="pageHeader"
/>
Expand Down Expand Up @@ -34,6 +28,7 @@
import LandingPageFooter from '@/components/landing/LandingPageFooter';
import ProvideCanonicalUrl from '@/components/provide/ProvideCanonicalUrl';
import versions from '../../pkg-versions';
import SkipLink from '@/components/generic/SkipLink';

export default {
name: 'LandingLayout',
Expand All @@ -42,7 +37,8 @@
LandingPageHeader,
LandingPageFooter,
PageCookiesWidget: () => import('@/components/page/PageCookiesWidget'),
ProvideCanonicalUrl
ProvideCanonicalUrl,
SkipLink
},

head() {
Expand Down
2 changes: 1 addition & 1 deletion packages/portal/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div data-qa="main content">
<LoadingSpinner
v-if="$fetchState.pending"
class="flex-md-row py-4 text-center"
Expand Down
52 changes: 52 additions & 0 deletions packages/portal/tests/unit/components/generic/SkipLink.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { createLocalVue, shallowMount } from '@vue/test-utils';
import sinon from 'sinon';

import SkipLink from '@/components/generic/SkipLink.vue';

const localVue = createLocalVue();

const factory = () => {
return shallowMount(SkipLink, {
localVue,
attachTo: document.body,
mocks: {
$t: (key) => key
},
stubs: ['b-button']
});
};

describe('components/generic/SkipLink', () => {
it('is rendered', async() => {
const wrapper = factory();

expect(wrapper.find('b-button-stub').exists()).toBe(true);
});

describe('when clicked', () => {
describe('and selected element does not exist', () => {
it('does not focus to the selected element', async() => {
const wrapper = factory();
const selectedElement = document.querySelector(wrapper.vm.selector);

wrapper.vm.handleClick();

expect(selectedElement).toBeFalsy();
});
});
describe('and selected element exists', () => {
it('sets focus to the selected element', async() => {
const wrapper = factory();
const mainElement = document.createElement('div');
mainElement.id = 'main';
document.body.appendChild(mainElement);
const selectedElement = document.querySelector(wrapper.vm.selector);
selectedElement.focus = sinon.spy();

wrapper.vm.handleClick();

expect(selectedElement.focus.called).toBe(true);
});
});
});
});
21 changes: 15 additions & 6 deletions packages/style/scss/buttons-links.scss
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,10 @@
}
}

a {
button {
&.skip-main {
left: -999px;
position: absolute;
left: -999px;
top: auto;
width: 1px;
height: 1px;
Expand All @@ -567,25 +567,34 @@ a {
}

&.skip-main:focus,
&.skip-main:active {
color: $white;
background-color: $greyblack;
&.skip-main:active,
&.skip-main.btn-secondary:not(:disabled):not(.disabled):active {
left: auto;
top: 70px;
width: 30%;
height: auto;
overflow: auto;
z-index: 999;
color: $white;
background-color: $greyblack;
margin: 10px 35%;
padding: 0.5rem;
border-radius: 1rem;
border: 4px solid $yellow;
text-align: center;
font-size: 1.2rem;
z-index: 999;
font-weight: 400;
text-transform: none;
text-decoration: underline;

@media (min-width: $bp-4k) {
top: calc(1.5 * 70px);
}

&:hover {
color: $white;
text-decoration: none;
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/features/common/layout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Feature: Page layout on all pages.
I want to be presented with an accessible and styled
layout for all pages.

@klaro-notice-not-dismissed
@klaro-notice-not-dismissed
Scenario: Moving to the main content using the skip-to-main functionality
When I visit the `home page`
And I see the Klaro banner
And I accept all Klaro cookies
And I press the TAB key
And I see the `main content accessibility link`
And I see the `skip to content link`
And I press the ENTER key
Then I should be on `/en#main`
Then the `main content` is highlighted

Scenario: Main navigation is visible
When I open the `home page`
Expand All @@ -29,4 +29,4 @@ Feature: Page layout on all pages.
Then I see an `item page`
Then The `top page` is active
And I press the TAB key
Then I see the `main content accessibility link`
Then I see the `skip to content link`
Loading