m-wrzr / streamlit-searchbox

Streamlit searchbox that dynamically updates and provides a list of suggestions based on a provided function
MIT License
253 stars 33 forks source link

Search box auto select #49

Closed weeks888 closed 4 months ago

weeks888 commented 5 months ago

Really love this component - Is it possible to pass through the current input value as opposed to the selected suggestion? The idea is for the users string to get searched by default but the suggestions are there if the user manually selects them (similar to how google works). Is this possible?

m-wrzr commented 4 months ago

Hey, thanks for the feedback! I'll add a new flag default_use_searchterm to return the current searchterm when a user is typing in the next version 👍 You could also track this by adding the searchterm to your search function, e.g.

def search(searchterm: str): ...
   st.session_state["current_search"] = searchterm
   ...

result = streamlit_seachbox(...)

if result is None and st.session_state.get("current_searchterm", None):
   # do sth with the current seach

Might have the benefit that you'd still know if it's a selected result by the user or not (if you don't use the new flag).