(Unwanted) Double click needed while using segmented control

Hello!
I have a problem when using segmented control. It appears that sometimes, the user needs to click twice, in order to select the options in the segmented control.

So, what I want for my app is that :

  1. I want to have a segmented control that traverse over multiple pages, so I save this in a session state.
  2. When the app starts, the segmented control should be automatically chosen to “A”.
  3. Now after this, the user can choose any sort they want (can be multiple)
  4. However, it is possible that the user do NOT choose anything, and this should be avoided. Let’s say the user accidentally unselect all choices, then a warning is shown (code not shown here). Now, when the user wants to reselect something, the user must do it twice, this leads to slight inconvenience.
    How can this problem be resolved?

Here is the code snippet :

if (“sort” not in st.session_state) :
st.session_state[“sort”] = st.sidebar.segmented_control(
“Choose sort”,
options=[“A”, “B”, “C”],
selection_mode=“multi”,
default=“A”,
)
else:
st.session_state[“sort”] = st.sidebar.segmented_control(
“Choose sort”,
options=[“A”, “B”, “C”],
selection_mode=“multi”,
default=st.session_state[“sort”],
)

Furthermore, I can’t remove the ‘default=st.session_state[“sort”]’ part, since removing it leads to the segmented control being automatically deselected when I go to another page in the app.

I tried to do debugging, and it seems that the problem occurs in the else block. After the user accidentally unselect every option, and then reselect any option, it is somehow NOT recognized until the user clicks it again.

Thank you in advance.