Skip to content

Commit eea2647

Browse files
committed
Remove tabindex from target after focus
1 parent aaa31f0 commit eea2647

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: src/VueSkipToSingle.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
</template>
1010

1111
<script>
12+
const focusedTags = new RegExp('^(a|select|input|button|textarea)', 'i')
13+
1214
export default {
1315
name: 'VueSkipToSingle',
1416
@@ -32,10 +34,10 @@ export default {
3234
if (!id) return
3335
const element = window.document.getElementById(id)
3436
if (!element) return
35-
if (!/^(a|select|input|button|textarea)/i.test(element.tagName.toLowerCase())) {
36-
element.setAttribute('tabindex', -1)
37-
}
37+
const isFocused = focusedTags.test(element.tagName.toLowerCase())
38+
!isFocused && element.setAttribute('tabindex', -1)
3839
element.focus()
40+
!isFocused && element.removeAttribute('tabindex')
3941
}
4042
}
4143
}

0 commit comments

Comments
 (0)