Why streamlit automatically switch to first tab when I impmenet the on_click function on button?

Hi everyone,

I’m using a Streamlit app that has three tabs, each containing buttons. When I click a button without using the on_click function, my application stays on the same tab. However, when I implement the on_click function and click a button, the app automatically switches back to the first tab, even though the on_click function does nothing.
Could someone help me understand why this is happening? I’m struggling to figure it out.

Thanks in advance!

The issue occurs with the latest version (1.45.0).

This is a known issue, but here’s a workaround Component in tab 2 triggers app to jump back to tab 1 · Issue #6257 · streamlit/streamlit · GitHub

If you’d like to see this behavior changed, you can add an upvote here `st.tabs` & `st.expander` - Improve handling of frontend state/mount · Issue #8239 · streamlit/streamlit · GitHub