File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -116,15 +116,35 @@ const { codeExamples } = Astro.props;
116
116
const buttons = document.querySelectorAll('.tab-btn');
117
117
const tabs = document.querySelectorAll('.tab-content');
118
118
119
+ function activateTab(tabIndex) {
120
+ buttons.forEach((b) => b.classList.toggle('active', b.dataset.tab === tabIndex));
121
+ tabs.forEach((t) => (t.style.display = t.dataset.tab === tabIndex ? 'block' : 'none'));
122
+ }
123
+
119
124
buttons.forEach((btn) => {
120
125
btn.addEventListener('click', () => {
121
126
const tab = btn.dataset.tab;
127
+ activateTab(tab);
122
128
123
- buttons.forEach((b) => b.classList.toggle('active', b.dataset.tab === tab));
124
- tabs.forEach((t) => (t.style.display = t.dataset.tab === tab ? 'block' : 'none'));
129
+ history.replaceState(null, '', `#example${parseInt(tab) + 1}`);
125
130
});
126
131
});
127
132
133
+ const hash = window.location.hash;
134
+ const match = hash.match(/^#example(\d+)$/i);
135
+ if (match) {
136
+ const tabIndex = String(parseInt(match[1], 10) - 1);
137
+ const targetBtn = document.querySelector(`.tab-btn[data-tab="${tabIndex}"]`);
138
+ if (targetBtn) {
139
+ activateTab(tabIndex);
140
+
141
+ const section = document.querySelector('.examples-section');
142
+ if (section) {
143
+ section.scrollIntoView({ behavior: 'smooth' });
144
+ }
145
+ }
146
+ }
147
+
128
148
function checkOverflow() {
129
149
const tabButtons = document.querySelector('.tab-buttons');
130
150
if (!tabButtons) return;
You can’t perform that action at this time.
0 commit comments