2024-02-18 03:34:27 +00:00
|
|
|
<script lang="ts">
|
2024-09-05 09:24:24 -04:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-02-18 03:34:27 +00:00
|
|
|
import Button from './button.svelte';
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
/**
|
|
|
|
|
* Target for the skip link to move focus to.
|
|
|
|
|
*/
|
|
|
|
|
target?: string;
|
|
|
|
|
text?: string;
|
|
|
|
|
}
|
2024-02-18 03:34:27 +00:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let { target = 'main', text = $t('skip_to_content') }: Props = $props();
|
|
|
|
|
|
|
|
|
|
let isFocused = $state(false);
|
2024-02-18 03:34:27 +00:00
|
|
|
|
|
|
|
|
const moveFocus = () => {
|
|
|
|
|
const targetEl = document.querySelector<HTMLElement>(target);
|
|
|
|
|
targetEl?.focus();
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-03-19 12:56:41 +00:00
|
|
|
<div class="absolute z-50 top-2 left-2 transition-transform {isFocused ? 'translate-y-0' : '-translate-y-10 sr-only'}">
|
2024-02-18 03:34:27 +00:00
|
|
|
<Button
|
2025-03-03 14:24:26 +00:00
|
|
|
size="sm"
|
2024-07-29 16:36:10 +02:00
|
|
|
rounded="none"
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={moveFocus}
|
|
|
|
|
onfocus={() => (isFocused = true)}
|
|
|
|
|
onblur={() => (isFocused = false)}
|
2024-02-18 03:34:27 +00:00
|
|
|
>
|
2024-09-05 09:24:24 -04:00
|
|
|
{text}
|
2024-02-18 03:34:27 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|