From bb2bda6a355b01426f9370f258cde7c7a2d7edc6 Mon Sep 17 00:00:00 2001 From: Martin Wurzer Date: Mon, 28 Oct 2024 10:35:26 +0100 Subject: [PATCH] fix pre-commit; remove 3.8 --- .github/workflows/ci.yml | 7 ++++--- README.md | 5 +++-- streamlit_searchbox/__init__.py | 15 ++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8aba709..1babc30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.10", "3.12"] + python-version: ["3.9", "3.11", "3.13"] steps: - uses: actions/checkout@v4 @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.10", "3.12"] + python-version: ["3.9", "3.11", "3.13"] steps: - uses: actions/checkout@v4 @@ -37,7 +37,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.10", "3.12"] + python-version: ["3.9", "3.11", "3.13"] + # TODO: test with latest streamlit version streamlit-version: ["1.25", "1.30", "1.31", "1.36"] steps: diff --git a/README.md b/README.md index 978c2e5..b9b194b 100644 --- a/README.md +++ b/README.md @@ -164,10 +164,10 @@ reset_function: Callable[[], None] | None = None Function that will be called when the combobox is reset. ```python -submit_function: Callable[[str], None] | None = None +submit_function: Callable[[Any], None] | None = None ``` -Function that will be called when a new option is selected. +Function that will be called when a new option is selected, with the selected option as argument. --- @@ -243,3 +243,4 @@ We welcome contributions from everyone. Here are a few ways you can help: - [@Jumitti](https://github.com/Jumitti) `st.rerun` compatibility - [@salmanrazzaq-94](https://github.com/salmanrazzaq-94) `st.fragment` support - [@hoggatt](https://github.com/hoggatt) `reset_function` +- [@bram49](https://github.com/bram49) `submit_function` diff --git a/streamlit_searchbox/__init__.py b/streamlit_searchbox/__init__.py index 634c29a..e34049c 100644 --- a/streamlit_searchbox/__init__.py +++ b/streamlit_searchbox/__init__.py @@ -209,7 +209,7 @@ def st_searchbox( debounce: int = 150, min_execution_time: int = MIN_EXECUTION_TIME_DEFAULT, reset_function: Callable[[], None] | None = None, - submit_function: Callable[[str], None] | None = None, + submit_function: Callable[[Any], None] | None = None, key: str = "searchbox", rerun_scope: Literal["app", "fragment"] = "app", **kwargs, @@ -254,8 +254,9 @@ def st_searchbox( within the component in some streamlit versions. Defaults to 0. reset_function (Callable[[], None], optional): Function that is called after the user reset the combobox. Defaults to None. - submit_function (Callable[[str], None], optional): - Function that is called after the user submits an option from the combobox. Defaults to None. + submit_function (Callable[[any], None], optional): + Function that is called after the user submits a new/unique option from the + combobox. Defaults to None. key (str, optional): Streamlit session key. Defaults to "searchbox". @@ -313,9 +314,13 @@ def st_searchbox( ) if interaction == "submit": - submit_value = st.session_state[key]["options_py"][value] if "options_py" in st.session_state[key] else value + submit_value = ( + st.session_state[key]["options_py"][value] + if "options_py" in st.session_state[key] + else value + ) - # Ensure submit_function only runs when value changed. Not on each fragment/app rerun + # ensure submit_function only runs when value changed if st.session_state[key]["result"] != submit_value: st.session_state[key]["result"] = submit_value if submit_function is not None: