PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/modules/block-library/tabs/view.js +25 -11 23.9.0 → 24.1.0 View file →
@@ -175,23 +175,37 @@
175 175 }
176 176 }
177 177 },
178 178 callbacks: {
179 - /**
180 - * When the tabs are initialized, we need to check if there is a hash in the url and if so if it exists in the current tabsList, set the active tab to that index.
181 - *
182 - */
183 - onTabsInit: () => {
179 + activateTabByHash: () => {
184 180 const { tabsList } = state;
185 - if (tabsList.length === 0) {
181 + if (!tabsList || tabsList.length === 0) {
186 182 return;
187 183 }
188 - const { hash } = window.location;
189 - const tabId = hash.replace("#", "");
190 - const tabIndex = tabsList.findIndex((t) => t === tabId);
191 - if (tabIndex >= 0) {
192 - actions.setActiveTab(tabIndex, true);
184 + const targetElement = document.querySelector(":target");
185 + if (!targetElement) {
186 + return;
193 187 }
188 + const panelIndex = tabsList.findIndex(
189 + (t) => t === targetElement.id
190 + );
191 + if (panelIndex >= 0) {
192 + actions.setActiveTab(panelIndex, true);
193 + return;
194 + }
195 + let panel = targetElement.closest(".wp-block-tab-panel");
196 + let tabIndex = -1;
197 + while (panel && tabIndex < 0) {
198 + tabIndex = tabsList.findIndex((t) => t === panel.id);
199 + panel = panel.parentElement?.closest(".wp-block-tab-panel") ?? null;
200 + }
201 + if (tabIndex < 0) {
202 + return;
203 + }
204 + actions.setActiveTab(tabIndex);
205 + window.setTimeout(() => {
206 + targetElement.scrollIntoView();
207 + }, 0);
194 208 }
195 209 }
196 210 },
197 211 {