Skip to content

Commit

Permalink
add reset function
Browse files Browse the repository at this point in the history
run a reset function (if specified) when the combobox is reset
  • Loading branch information
hoggatt committed Sep 13, 2023
1 parent 3d7c324 commit 495c1ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ To customize the combobox you can pass the following arguments:
```python
selected_value = st_combobox(
search_function: Callable[[str], List[any]],
reset_function: Callable[[], None] = None,
placeholder: str = "Search ...",
label: str = None,
default: any = None,
Expand All @@ -74,6 +75,12 @@ search_function: Callable[[str], List[any]]
```
<br/>

Function that will be called when the combobox is reset.
```python
reset_function: Callable[[], None] = None
```
<br/>

Placeholder text when the combobox is blank.
```python
placeholder: str = "Search ..."
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="st-combobox",
version="1.0.0",
version="1.0.1",
author="hoggatt",
description="Streamlit AutoComplete ComboBox",
long_description=long_description,
Expand Down
14 changes: 11 additions & 3 deletions st_combobox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _get_value(value: any) -> any:
@wrap_inactive_session
def st_combobox(
search_function: Callable[[str], List[any]],
reset_function: Callable[[], None] = None,
placeholder: str = "Search ...",
label: str = None,
default: any = None,
Expand All @@ -105,6 +106,8 @@ def st_combobox(
Args:
search_function (Callable[[str], List[any]]):
Function that is called to fetch new suggestions after user input.
reset_function (Callable[[], None], optional):
Function that is called after the user has reset the combobox. Defaults to None.
placeholder (str, optional):
Label shown in the combobox. Defaults to "Search ...".
label (str, optional):
Expand Down Expand Up @@ -143,7 +146,9 @@ def st_combobox(

# load stuff the first run if called for
if blank_search_value is not None:
_process_search(search_function, key, blank_search_value, rerun_on_update, stop_on_update)
_process_search(
search_function, key, blank_search_value, rerun_on_update, stop_on_update
)

# everything here is passed to react as this.props.args
react_state = _get_react_component(
Expand Down Expand Up @@ -185,7 +190,11 @@ def st_combobox(

if blank_search_value is not None:
# reset default search if specified (must reload for this to actually show, hitting backspace again works)
_process_search(search_function, key, blank_search_value, rerun_on_update, stop_on_update)
_process_search(
search_function, key, blank_search_value, rerun_on_update, stop_on_update
)
if reset_function is not None:
reset_function()

return default

Expand All @@ -194,4 +203,3 @@ def st_combobox(
return None
else:
return st.session_state[key]["result"]

0 comments on commit 495c1ee

Please sign in to comment.