diff --git a/.changeset/proud-mirrors-remain.md b/.changeset/proud-mirrors-remain.md new file mode 100644 index 0000000000..e18062ad3a --- /dev/null +++ b/.changeset/proud-mirrors-remain.md @@ -0,0 +1,6 @@ +--- +"@gradio/accordion": patch +"gradio": patch +--- + +fix:Store `gr.Accordion`'s `open` value diff --git a/demo/blocks_flipper/run.ipynb b/demo/blocks_flipper/run.ipynb index 8fc016f282..716f3af30f 100644 --- a/demo/blocks_flipper/run.ipynb +++ b/demo/blocks_flipper/run.ipynb @@ -1 +1 @@ -{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_flipper"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import numpy as np\n", "import gradio as gr\n", "\n", "\n", "def flip_text(x):\n", " return x[::-1]\n", "\n", "\n", "def flip_image(x):\n", " return np.fliplr(x)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Flip text or image files using this demo.\")\n", " with gr.Tab(\"Flip Text\"):\n", " text_input = gr.Textbox()\n", " text_output = gr.Textbox()\n", " text_button = gr.Button(\"Flip\")\n", " with gr.Tab(\"Flip Image\"):\n", " with gr.Row():\n", " image_input = gr.Image()\n", " image_output = gr.Image()\n", " image_button = gr.Button(\"Flip\")\n", "\n", " with gr.Accordion(\"Open for More!\"):\n", " gr.Markdown(\"Look at me...\")\n", "\n", " text_button.click(flip_text, inputs=text_input, outputs=text_output)\n", " image_button.click(flip_image, inputs=image_input, outputs=image_output)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} \ No newline at end of file +{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_flipper"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import numpy as np\n", "import gradio as gr\n", "\n", "\n", "def flip_text(x):\n", " return x[::-1]\n", "\n", "\n", "def flip_image(x):\n", " return np.fliplr(x)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Flip text or image files using this demo.\")\n", " with gr.Tab(\"Flip Text\"):\n", " text_input = gr.Textbox()\n", " text_output = gr.Textbox()\n", " text_button = gr.Button(\"Flip\")\n", " with gr.Tab(\"Flip Image\"):\n", " with gr.Row():\n", " image_input = gr.Image()\n", " image_output = gr.Image()\n", " image_button = gr.Button(\"Flip\")\n", "\n", " with gr.Accordion(\"Open for More!\", open=False):\n", " gr.Markdown(\"Look at me...\")\n", " temp_slider = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, interactive=True, label=\"Slide me\")\n", " temp_slider.change(lambda x:x, [temp_slider])\n", "\n", " text_button.click(flip_text, inputs=text_input, outputs=text_output)\n", " image_button.click(flip_image, inputs=image_input, outputs=image_output)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} \ No newline at end of file diff --git a/demo/blocks_flipper/run.py b/demo/blocks_flipper/run.py index 29753508d9..6bcdb5987c 100644 --- a/demo/blocks_flipper/run.py +++ b/demo/blocks_flipper/run.py @@ -22,8 +22,10 @@ with gr.Blocks() as demo: image_output = gr.Image() image_button = gr.Button("Flip") - with gr.Accordion("Open for More!"): + with gr.Accordion("Open for More!", open=False): gr.Markdown("Look at me...") + temp_slider = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, interactive=True, label="Slide me") + temp_slider.change(lambda x:x, [temp_slider]) text_button.click(flip_text, inputs=text_input, outputs=text_output) image_button.click(flip_image, inputs=image_input, outputs=image_output) diff --git a/js/accordion/Index.svelte b/js/accordion/Index.svelte index 6e412f51f2..1a1c071426 100644 --- a/js/accordion/Index.svelte +++ b/js/accordion/Index.svelte @@ -23,7 +23,7 @@ {...loading_status} /> - + diff --git a/js/accordion/shared/Accordion.svelte b/js/accordion/shared/Accordion.svelte index a280324a2c..06bcb573cc 100644 --- a/js/accordion/shared/Accordion.svelte +++ b/js/accordion/shared/Accordion.svelte @@ -1,15 +1,23 @@ - -
+
diff --git a/js/app/test/blocks_flipper.spec.ts b/js/app/test/blocks_flipper.spec.ts new file mode 100644 index 0000000000..8dcb3e99d4 --- /dev/null +++ b/js/app/test/blocks_flipper.spec.ts @@ -0,0 +1,9 @@ +import { test, expect } from "@gradio/tootils"; + +test("accordion stays open when interacting with the slider", async ({ + page +}) => { + await page.getByRole("button", { name: "Open for More! ▼" }).click(); + await page.getByLabel("range slider for Slide me").fill("0.5"); + await expect(page.getByText("Look at me...")).toBeVisible(); +});