Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

va-skip-link #3720

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions packages/ui/src/components/va-skip-link/VaSkipLink.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { VaSkipLink } from './'
Roman4437 marked this conversation as resolved.
Show resolved Hide resolved

export default {
title: 'VaSkipLink',
component: VaSkipLink,
}

export const Target = () => ({
Roman4437 marked this conversation as resolved.
Show resolved Hide resolved
components: { VaSkipLink },
template: `
<va-skip-link target="#target">
[skip link]
</va-skip-link>
<div :style="{ height: '100dvh' }">
[not target]
</div>
<div
id="target"
:style="{ height: '100dvh' }"
>
[target]
</div>
`,
})

export const PositionTopLeft = () => ({
Roman4437 marked this conversation as resolved.
Show resolved Hide resolved
components: { VaSkipLink },
template: `
<va-skip-link position="top-left">
[top-left]
</va-skip-link>
`,
})

export const PositionTopRight = () => ({
components: { VaSkipLink },
template: `
<va-skip-link position="top-right">
[top-right]
</va-skip-link>
`,
})

export const PositionBottomLeft = () => ({
components: { VaSkipLink },
template: `
<va-skip-link position="bottom-left">
[bottom-left]
</va-skip-link>
`,
})

export const PositionBottomRight = () => ({
components: { VaSkipLink },
template: `
<va-skip-link position="bottom-right">
[bottom-right]
</va-skip-link>
`,
})
47 changes: 47 additions & 0 deletions packages/ui/src/components/va-skip-link/VaSkipLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<a
Roman4437 marked this conversation as resolved.
Show resolved Hide resolved
class="va-skip-link"
role="link"
:href="target"
:style="position"
>
<slot />
</a>
</template>

<script lang="ts">
import { PropType, defineComponent } from 'vue'
import { usePosition } from './hooks/usePosition'

export default defineComponent({
name: 'VaSkipLink',
props: {
target: { type: String, default: '' },
position: {
type: String as PropType<'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'>,
default: 'bottom-right',
validator: (v: string) => ['top-right', 'top-left', 'bottom-right', 'bottom-left'].includes(v),
},
},

setup (props) {
const { position } = usePosition(props)

return { position }
},
})
</script>

<style lang="scss">
.va-skip-link {
display: flex;
position: fixed;
opacity: 0;
pointer-events: none;

&:focus {
opacity: 1;
pointer-events: inherit;
}
}
</style>
18 changes: 18 additions & 0 deletions packages/ui/src/components/va-skip-link/hooks/usePosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const usePosition = (props: {
position: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
}) => {
const getPosition = () => {
const positionMap = {
'top-right': { top: '1rem', right: '1rem' },
'top-left': { top: '1rem', left: '1rem' },
'bottom-right': { bottom: '1rem', right: '1rem' },
'bottom-left': { bottom: '1rem', left: '1rem' },
}

return positionMap[props.position]
}

const position = getPosition()

return { position }
}
4 changes: 4 additions & 0 deletions packages/ui/src/components/va-skip-link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import withConfigTransport from '../../services/config-transport/withConfigTransport'
import _VaSkipLink from './VaSkipLink.vue'

export const VaSkipLink = withConfigTransport(_VaSkipLink)
11 changes: 11 additions & 0 deletions packages/ui/src/components/va-skip-link/tests/VaSkipLink.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, it, expect } from 'vitest'
import { mountWithGlobalConfig } from '../../../utils/unit-test-utils'

import VaSkipLink from '../VaSkipLink.vue'

describe('VaSkipLink', () => {
it('should render without an error', () => {
const wrapper = mountWithGlobalConfig(VaSkipLink)
expect(wrapper.exists()).toBeTruthy()
})
})