Skip to content

Commit cc543ca

Browse files
committed
fix: preserve tab state
1 parent 7c1f640 commit cc543ca

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

scripts/editor-support.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ function getState(block) {
2121
if (block.matches('.carousel')) {
2222
return block.dataset.activeSlide;
2323
}
24+
if (block.matches('.tabs')) {
25+
return [...block.querySelectorAll('.tabs-panel[aria-hidden="false"]')].map(
26+
(panel) => panel.dataset.aueResource,
27+
);
28+
}
29+
2430
return null;
2531
}
2632

@@ -34,6 +40,11 @@ function setState(block, state) {
3440
block.style.display = null;
3541
showSlide(block, state, 'instant');
3642
}
43+
if (block.matches('.tabs')) {
44+
block.querySelectorAll('.tabs-panel').forEach((panel) => {
45+
panel.setAttribute('aria-hidden', !state.includes(panel.dataset.aueResource));
46+
});
47+
}
3748
}
3849

3950
async function applyChanges(event) {
@@ -146,7 +157,7 @@ function handleSelection(event) {
146157
}
147158

148159
if (block && block.matches('.tabs')) {
149-
const tabs = [...block.querySelectorAll('.tabs-panel > div')];
160+
const tabs = [...block.querySelectorAll('.tabs-panel')];
150161
const index = tabs.findIndex((tab) => tab.dataset.aueResource === resource);
151162
if (index !== -1) {
152163
block.querySelectorAll('.tabs-list button')[index]?.click();

0 commit comments

Comments
 (0)