gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.88k stars 2.57k forks source link

Add id, class, and or attribute to a Tab's button #5585

Closed CurtisDS closed 1 year ago

CurtisDS commented 1 year ago

Is your feature request related to a problem? Please describe.
I have Javascript that is added to the page which will activate a tab during specific instances. I do this by scanning the tab buttons in the tab bar and checking the label of each one to know which one to activate, however, an issue has popped up where someone is using a translation extension that swaps out the labels on the buttons and that breaks the functionality I was using to find the tab button.

Describe the solution you'd like
If we were able to add an id, class, or attribute to the tab's button I could then use that to find the correct button instead of a string compare on the label.

Example:

with gr.Tab(
    my_tab_label,
    elem_id=f"my_tab_id",
    elem_classes="my_tab_class",
    btn_id=f"my_tabs_btn_id",
    btn_classes="my_tabs_btn_class"
):

Would result in:

<div class="tabs gradio-tabs" id="tabs">
    <div class="tab-nav">
        <button id="my_tabs_btn_id" class="my_tabs_btn_class">my_tab_label</button>
    </div>
    <div id="my_tab_id" class="tabitem gradio-tabitem my_tab_class">
        <!-- tab content -->
    </div>
</div>
abidlabs commented 1 year ago

I'm hesitant to add two separate parameters. However, what if we were to automatically set the btn id to be "{elem_id}-btn", allowing you to target it directly?

CurtisDS commented 1 year ago

that would be perfect