m-wrzr / streamlit-searchbox

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

Search box auto select #49

Open weeks888 opened 1 week ago

weeks888 commented 1 week 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 2 days 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).