@backstage/plugin-techdocs
Version:
The Backstage plugin that renders technical documentation for your components
29 lines (27 loc) • 966 B
JavaScript
function addNavLinkKeyboardToggle() {
return (element) => {
const navLabels = element.querySelectorAll("label.md-nav__link[for]");
navLabels.forEach((label) => {
label.setAttribute("tabIndex", "0");
label.addEventListener("keydown", (event) => {
const keyboardEvent = event;
if (keyboardEvent.key === "Enter" || keyboardEvent.key === " ") {
const forId = label.getAttribute("for");
if (!forId) return;
const checkbox = element.querySelector(
`#${forId}`
);
if (checkbox && checkbox.type === "checkbox") {
checkbox.checked = !checkbox.checked;
checkbox.dispatchEvent(new Event("change", { bubbles: true }));
event.preventDefault();
event.stopPropagation();
}
}
});
});
return element;
};
}
export { addNavLinkKeyboardToggle };
//# sourceMappingURL=addNavLinkKeyboardToggle.esm.js.map