Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/blocks_xray/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def ct_model(diseases, img):
)

with gr.Tabs():
with gr.TabItem("X-ray"):
with gr.TabItem("X-ray") as x_tab:
with gr.Row():
xray_scan = gr.Image()
xray_results = gr.JSON()
Expand Down
4 changes: 2 additions & 2 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ def __init__(
def get_template_context(self):
return {"label": self.label, **super().get_template_context()}

def change(self, fn: Callable, inputs: List[Component], outputs: List[Component]):
def select(self, fn: Callable, inputs: List[Component], outputs: List[Component]):
"""
Parameters:
fn: Callable function
inputs: List of inputs
outputs: List of outputs
Returns: None
"""
self.set_event_trigger("change", fn, inputs, outputs)
self.set_event_trigger("select", fn, inputs, outputs)


class BlockFunction:
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/app/src/components/TabItem/Tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
export let label: string;
</script>

<TabItem name={label}>
<TabItem name={label} on:select>
<slot />
</TabItem>
10 changes: 7 additions & 3 deletions ui/packages/tabs/src/TabItem.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<script lang="ts">
import { getContext, onDestroy } from "svelte";
import { getContext, onMount, createEventDispatcher, tick } from "svelte";
import { TABS } from "./Tabs.svelte";

export let name: string;

const dispatch = createEventDispatcher<{ select: undefined }>();
const id = {};

const { register_tab, unregister_tab, selected_tab } = getContext(TABS);

register_tab({ name, id });

onDestroy(() => {
unregister_tab({ name, id });
onMount(() => {
return () => unregister_tab({ name, id });
});

$: $selected_tab === id && tick().then(() => dispatch("select"));
</script>

{#if $selected_tab === id}
Expand Down
6 changes: 3 additions & 3 deletions ui/packages/workbench/src/routes/tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
</script>

<Tabs>
<TabItem name="tab 1">
<TabItem name="tab 1" on:select={() => console.log("tab 1")}>
<h1>HELLO FROM TAB 1</h1>
</TabItem>

<TabItem name="tab 2">
<TabItem name="tab 2" on:select={() => console.log("tab 2")}>
<h1>HELLO FROM TAB 2</h1>
</TabItem>

<TabItem name="tab 3">
<TabItem name="tab 3" on:select={() => console.log("tab 3")}>
<h1>HELLO FROM TAB 2</h1>
<p>I am text</p>
<blockquote>I am a quote</blockquote>
Expand Down