@hortonstudio/main 1.1.28 → 1.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/toc.js +29 -0
package/package.json
CHANGED
package/utils/toc.js
CHANGED
@@ -44,6 +44,35 @@ export async function init() {
|
|
44
44
|
link.appendChild(number);
|
45
45
|
link.appendChild(document.createTextNode(heading.textContent));
|
46
46
|
|
47
|
+
// Add click handler to prevent focus on mouse clicks but allow keyboard focus
|
48
|
+
link.addEventListener('click', (e) => {
|
49
|
+
// Prevent default to handle scrolling ourselves
|
50
|
+
e.preventDefault();
|
51
|
+
|
52
|
+
const targetSection = document.getElementById(sectionId);
|
53
|
+
if (targetSection) {
|
54
|
+
// Scroll to the section
|
55
|
+
targetSection.scrollIntoView({ behavior: 'smooth' });
|
56
|
+
|
57
|
+
// Don't focus the target element on mouse clicks (Safari focus issue)
|
58
|
+
// Focus will still work with keyboard navigation (Enter key, etc.)
|
59
|
+
}
|
60
|
+
});
|
61
|
+
|
62
|
+
// Handle keyboard navigation (Enter/Space) to maintain accessibility
|
63
|
+
link.addEventListener('keydown', (e) => {
|
64
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
65
|
+
e.preventDefault();
|
66
|
+
|
67
|
+
const targetSection = document.getElementById(sectionId);
|
68
|
+
if (targetSection) {
|
69
|
+
targetSection.scrollIntoView({ behavior: 'smooth' });
|
70
|
+
// Allow focus for keyboard users
|
71
|
+
targetSection.focus();
|
72
|
+
}
|
73
|
+
}
|
74
|
+
});
|
75
|
+
|
47
76
|
// Add item to the TOC list
|
48
77
|
tocList.appendChild(tocItem);
|
49
78
|
});
|