Skip to content

Commit 3024e7b

Browse files
author
gambletan
committed
fix: Tab initialized with interactive=False cannot be updated to True
When a Tab's `interactive` prop changed via gr.Tab(interactive=True), the `tabs` array in Tabs.svelte was updated by register_tab, but the `visible_tabs` and `overflow_tabs` arrays (which the template actually renders from) retained stale tab objects. These arrays are only refreshed by handle_menu_overflow, which is async (awaits tick()) and relies on DOM measurements. Unlike `visible` changes—which trigger DOM structural changes in the hidden measurement container, cascading through element bindings to re-trigger handle_menu_overflow—`interactive` changes cause no DOM structural changes, so visible_tabs never gets the updated tab data. The fix adds a synchronous reactive block that keeps visible_tabs and overflow_tabs tab objects in sync with the canonical tabs array whenever any tab property changes. Closes #13033 Signed-off-by: Tan <alvinttang@gmail.com>
1 parent 73d4065 commit 3024e7b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

js/tabs/shared/Tabs.svelte

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@
3232
3333
$: has_tabs = tabs.length > 0;
3434
35+
// Keep visible_tabs and overflow_tabs in sync with tabs data.
36+
// handle_menu_overflow determines which tabs go into which list (based on
37+
// DOM measurements), but it is async (awaits tick()) so property updates
38+
// like interactive changes can be missed. This reactive block ensures the
39+
// tab objects inside visible_tabs/overflow_tabs stay current.
40+
$: {
41+
if (tabs) {
42+
visible_tabs = visible_tabs.map((vt) => {
43+
if (!vt) return vt;
44+
const updated = tabs.find((t) => t?.id === vt.id);
45+
return updated ?? vt;
46+
});
47+
overflow_tabs = overflow_tabs.map((ot) => {
48+
if (!ot) return ot;
49+
const updated = tabs.find((t) => t?.id === ot.id);
50+
return updated ?? ot;
51+
});
52+
}
53+
}
54+
3555
let tab_nav_el: HTMLDivElement;
3656
3757
const selected_tab = writable<false | number | string>(

0 commit comments

Comments
 (0)