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;
116116 const buttons = document.querySelectorAll('.tab-btn');
117117 const tabs = document.querySelectorAll('.tab-content');
118118
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+
119124 buttons.forEach((btn) => {
120125 btn.addEventListener('click', () => {
121126 const tab = btn.dataset.tab;
127+ activateTab(tab);
122128
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}`);
125130 });
126131 });
127132
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+
128148 function checkOverflow() {
129149 const tabButtons = document.querySelector('.tab-buttons');
130150 if (!tabButtons) return;
You can’t perform that action at this time.
0 commit comments