Skip to content

Commit fdea86d

Browse files
committed
feat: Emulate focus-within to support IE11
1 parent 1e5407f commit fdea86d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/VueSkipTo.vue

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<template>
2-
<div class="vue-skip-to">
3-
<component :is="comp" v-bind="props" />
2+
<div
3+
class="vue-skip-to"
4+
:class="{ 'focused': focused }"
5+
>
6+
<component
7+
@focused="focusWithin"
8+
@focus-within="focusWithin"
9+
:is="comp"
10+
v-bind="props"
11+
/>
412
</div>
513
</template>
614

@@ -26,6 +34,12 @@ export default {
2634
}
2735
},
2836
37+
data () {
38+
return {
39+
focused: false
40+
}
41+
},
42+
2943
computed: {
3044
isList () {
3145
return Array.isArray(this.to)
@@ -39,6 +53,12 @@ export default {
3953
if (this.isList) return { listLabel: this.listLabel, to: this.to }
4054
return { label: this.label, to: this.to }
4155
}
56+
},
57+
58+
methods: {
59+
focusWithin (val) {
60+
this.focused = val
61+
}
4262
}
4363
}
4464
</script>
@@ -62,7 +82,7 @@ export default {
6282
border-width: 0;
6383
}
6484
65-
.vue-skip-to:focus-within, .vue-skip-to:focus, .vue-skip-to:hover {
85+
.vue-skip-to.focused, .vue-skip-to:hover {
6686
left: 0;
6787
top: 0;
6888
clip: auto;

src/VueSkipToList.vue

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
>
1212
<VueSkipToSingle
1313
:to="el.anchor"
14+
@focused="$emit('focus-within', $event)"
1415
:aria-label="el.ariaLabel || el.label"
1516
>
1617
{{ el.label }}

src/VueSkipToSingle.vue

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<a
33
:href="to"
44
@click.prevent="handleFocusElement"
5+
@focus="$emit('focused', true)"
6+
@blur="$emit('focused', false)"
57
class="vue-skip-to__link"
68
>
79
<slot>{{ label }}</slot>

0 commit comments

Comments
 (0)