St.expander doesn't close after user opens it manually

Summary

(see this issue

When an un-expanded (henceforth folded) st.expander is expanded by a user by clicking on it, it is not possible to fold the st.expander .

Steps to reproduce

Code snippet:

import streamlit as st


def expanded():
    st.session_state["expanded"] = False


with st.expander("Expander", st.session_state.get("expanded", True)):
    st.text(f"{st.session_state.get('expanded', True) = }")
    st.button("Fold", on_click=expanded)```

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

**Expected behavior:**

Expanded `st.expander` folds again after clicking the `Fold` button for the second time.

**Actual behavior:**

See a gif here: https://github.com/streamlit/streamlit/issues/6370



### Debug info

Streamlit version: 1.20
Python version: 3.9.16
Operating System: MacOS Ventura 13.2.1
Browser: Google Chrome
Virtual environment: Pipenv

Hi @sTomerG, have a read through this thread: Closing current expander and opening next by button-press

Cheers

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.