Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/.vuepress/theme/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import {
getPageWithRelativePath,
fixDoubleSlashes,
getSameContentForVersion,
makeOverflowingContainersFocusable,
} from "../util";

import { getStorage, setStorage, unsetStorage } from "../Storage";
Expand All @@ -187,7 +188,10 @@ export default {

watch: {
'$route.path'() {
this.$refs.backToTop.focus()
this.$refs.backToTop.focus();
this.$nextTick(function () {
makeOverflowingContainersFocusable();
});
}
},

Expand Down Expand Up @@ -284,6 +288,10 @@ export default {
this.isSidebarOpen = false;
});

this.$nextTick(function () {
makeOverflowingContainersFocusable();
});

// temporary means of scrolling to URL hash on load
// https://github.com/vuejs/vuepress/issues/2428
const hash = document.location.hash;
Expand Down
15 changes: 15 additions & 0 deletions docs/.vuepress/theme/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,21 @@ function getAnchorHash(path) {
return false;
}

/**
* Adds tabindex="0" to all containers (e.g., <pre>, <div>, etc.) that have overflowing content,
* making them focusable for keyboard navigation accessibility.
*
* This utility is typically used to improve accessibility for code blocks or other scrollable regions,
* allowing users to focus and scroll them using the keyboard.
*/
export function makeOverflowingContainersFocusable() {
document.querySelectorAll('pre,.toggle-tip .wrapper,.viewport.limit-height').forEach(el => {
if (el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight) {
el.setAttribute('tabindex', '0');
}
});
}

/**
* Returns doc set base paths combinations with their configs,
* accounting for set base, version, and/or language.
Expand Down