Skip to content

Commit

Permalink
feat: Emulate focus-within to support IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
ktquez committed Sep 4, 2020
1 parent 1e5407f commit fdea86d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/VueSkipTo.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<div class="vue-skip-to">
<component :is="comp" v-bind="props" />
<div
class="vue-skip-to"
:class="{ 'focused': focused }"
>
<component
@focused="focusWithin"
@focus-within="focusWithin"
:is="comp"
v-bind="props"
/>
</div>
</template>

Expand All @@ -26,6 +34,12 @@ export default {
}
},
data () {
return {
focused: false
}
},
computed: {
isList () {
return Array.isArray(this.to)
Expand All @@ -39,6 +53,12 @@ export default {
if (this.isList) return { listLabel: this.listLabel, to: this.to }
return { label: this.label, to: this.to }
}
},
methods: {
focusWithin (val) {
this.focused = val
}
}
}
</script>
Expand All @@ -62,7 +82,7 @@ export default {
border-width: 0;
}
.vue-skip-to:focus-within, .vue-skip-to:focus, .vue-skip-to:hover {
.vue-skip-to.focused, .vue-skip-to:hover {
left: 0;
top: 0;
clip: auto;
Expand Down
1 change: 1 addition & 0 deletions src/VueSkipToList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
>
<VueSkipToSingle
:to="el.anchor"
@focused="$emit('focus-within', $event)"
:aria-label="el.ariaLabel || el.label"
>
{{ el.label }}
Expand Down
2 changes: 2 additions & 0 deletions src/VueSkipToSingle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<a
:href="to"
@click.prevent="handleFocusElement"
@focus="$emit('focused', true)"
@blur="$emit('focused', false)"
class="vue-skip-to__link"
>
<slot>{{ label }}</slot>
Expand Down

0 comments on commit fdea86d

Please sign in to comment.