@gradio/tabs 0.5.8 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @gradio/tabs
2
2
 
3
+ ## 0.5.9
4
+
5
+ ### Fixes
6
+
7
+ - [#13048](https://github.com/gradio-app/gradio/pull/13048) [`a5d4096`](https://github.com/gradio-app/gradio/commit/a5d40965bba21a832da522127048926b71c1a6dd) - Fix Tab Interactive Bug. Thanks @freddyaboulton!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/utils@0.12.2
12
+
13
+ ## 0.5.8
14
+
15
+ ### Dependency updates
16
+
17
+ - @gradio/utils@0.12.1
18
+
3
19
  ## 0.5.8
4
20
 
5
21
  ### Dependency updates
@@ -30,6 +30,25 @@
30
30
  let overflow_menu_open = false;
31
31
  let overflow_menu: HTMLElement;
32
32
 
33
+ // Track which tab orders have been registered by mounted TabItem components.
34
+ // Once a TabItem mounts and calls register_tab, it manages its own tab entry
35
+ // via _set_data -> register_tab, so _sync_tabs should not overwrite it.
36
+ let mounted_tab_orders: Set<number> = new Set();
37
+
38
+ // When initial_tabs changes (e.g. a non-mounted tab's props were updated),
39
+ // sync the internal tabs array so the tab buttons reflect the new state.
40
+ // Using a function call so the $: dependency is only on initial_tabs,
41
+ // not on tabs (which would cause a loop with register_tab).
42
+ $: _sync_tabs(initial_tabs);
43
+
44
+ function _sync_tabs(new_tabs: Tab[]): void {
45
+ for (let i = 0; i < new_tabs.length; i++) {
46
+ if (new_tabs[i] && !mounted_tab_orders.has(i)) {
47
+ tabs[i] = new_tabs[i];
48
+ }
49
+ }
50
+ }
51
+
33
52
  $: has_tabs = tabs.length > 0;
34
53
 
35
54
  let tab_nav_el: HTMLDivElement;
@@ -59,6 +78,7 @@
59
78
 
60
79
  setContext(TABS, {
61
80
  register_tab: (tab: Tab, order: number) => {
81
+ mounted_tab_orders.add(order);
62
82
  tabs[order] = tab;
63
83
 
64
84
  if ($selected_tab === false && tab.visible !== false && tab.interactive) {
@@ -68,6 +88,7 @@
68
88
  return order;
69
89
  },
70
90
  unregister_tab: (tab: Tab, order: number) => {
91
+ mounted_tab_orders.delete(order);
71
92
  if ($selected_tab === tab.id) {
72
93
  $selected_tab = tabs[0]?.id || false;
73
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/tabs",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -17,10 +17,10 @@
17
17
  "./package.json": "./package.json"
18
18
  },
19
19
  "dependencies": {
20
- "@gradio/utils": "^0.12.0"
20
+ "@gradio/utils": "^0.12.2"
21
21
  },
22
22
  "devDependencies": {
23
- "@gradio/preview": "^0.16.0"
23
+ "@gradio/preview": "^0.16.2"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "svelte": "^5.48.0"
@@ -30,6 +30,25 @@
30
30
  let overflow_menu_open = false;
31
31
  let overflow_menu: HTMLElement;
32
32
 
33
+ // Track which tab orders have been registered by mounted TabItem components.
34
+ // Once a TabItem mounts and calls register_tab, it manages its own tab entry
35
+ // via _set_data -> register_tab, so _sync_tabs should not overwrite it.
36
+ let mounted_tab_orders: Set<number> = new Set();
37
+
38
+ // When initial_tabs changes (e.g. a non-mounted tab's props were updated),
39
+ // sync the internal tabs array so the tab buttons reflect the new state.
40
+ // Using a function call so the $: dependency is only on initial_tabs,
41
+ // not on tabs (which would cause a loop with register_tab).
42
+ $: _sync_tabs(initial_tabs);
43
+
44
+ function _sync_tabs(new_tabs: Tab[]): void {
45
+ for (let i = 0; i < new_tabs.length; i++) {
46
+ if (new_tabs[i] && !mounted_tab_orders.has(i)) {
47
+ tabs[i] = new_tabs[i];
48
+ }
49
+ }
50
+ }
51
+
33
52
  $: has_tabs = tabs.length > 0;
34
53
 
35
54
  let tab_nav_el: HTMLDivElement;
@@ -59,6 +78,7 @@
59
78
 
60
79
  setContext(TABS, {
61
80
  register_tab: (tab: Tab, order: number) => {
81
+ mounted_tab_orders.add(order);
62
82
  tabs[order] = tab;
63
83
 
64
84
  if ($selected_tab === false && tab.visible !== false && tab.interactive) {
@@ -68,6 +88,7 @@
68
88
  return order;
69
89
  },
70
90
  unregister_tab: (tab: Tab, order: number) => {
91
+ mounted_tab_orders.delete(order);
71
92
  if ($selected_tab === tab.id) {
72
93
  $selected_tab = tabs[0]?.id || false;
73
94
  }