New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix programmatic tab selection #7916
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/56c24885b35b84121678e006a5094952ca9d67d2/gradio-4.25.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@56c24885b35b84121678e006a5094952ca9d67d2#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice catch. Thanks @aliabid94!
We should probably lint against 'shadowing' variables. I wonder if this fixes #7786 as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice @aliabid94 ! Can we add a test for this? It's regressed before
Added tests. While I was adding tests, I caught an error that wouldn't show up in dev mode for some reason: If a gr.Tabs() had |
actually my solution won't work in the case that an app programmatically tries to set the selected tab to the same tab a second time after a user moved away from that tab. Is there any way for gradio to know if the selected tab being passed is the result of an event listener output, or just a redraw resetting the prop? |
What is the actually problem, sorry. In principle we shouldn't need to know the difference. |
Yep, when selecting away from Tab C, I'm unable to select it again: Sounds like the same problem you're referring to @aliabid94. However, removing the new logic that was added in Edit: I realise you added these changes due to
|
This feels like the accordion thing tbh. Gonna take a closer look. |
Sorry let me clarify. The issue I was trying to fix with selected, _selected, and old_selected_prop is that event listeners were causing the component to re-render, which was causing the props to be reset to their set values. So the selected tab would get reset to the constructor-set value. So if there was a gr.Tabs(selected="b") setting the default to "b", and a user clicked away to tab "a", when an event listener triggered a re-render, the tab would reset to "b". |
I see. That does sound very similar to the accordion issues where it resets to the default. |
@aliabid94 I have just opened #7963 to fix the accordion 'reset' issue, and this feels similar. When that is merged in i think if you merge main into this it may fix the remaining issue you are having. |
#7963 is merged now, I've updated this branch with main. Could you retest now @aliabid94? |
Works great, thanks @pngwn! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for fixing this and adding those extra tests @aliabid94!
* changes * changes * add changeset * changes * add changeset * changes * add changeset --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
So, how do I change the active tab programmatically? (not from a button, just from code). |
selected
was not being respected for tabitems, because theid
property of a tabitem was being overwritten internally. Renamed internal use ofid
to_id
.Test with:
Fixes: #7726