m-wrzr / streamlit-searchbox

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

Add `blank_search_value` option #57

Closed hoggatt closed 2 months ago

hoggatt commented 2 months ago

I have a use-case where I'd like there to be a default search if my search is blank. I've added this feature to a fork here (search blank_search_value).

Unfortunately this fork is out of sync with yours, so I can't directly contribute a pull request. Would it be possible to add this feature?

Here is the doc you can add to the readme:


blank_search_value: str = None

If not None, will set the default search value when the box is initialized or reset.

hoggatt commented 2 months ago

In theory, your default option should work, but in practice when I click on the searchbox, the default search doesn't show up.

Furthermore, if I reset or clear the box the default search does not show up again.

m-wrzr commented 2 months ago

Hey, just for my understanding: this is not about the default that is returned in python but the text that is shown in the searchbox? So setting something like the initial search term?

hoggatt commented 2 months ago

Hey, just for my understanding: this is not about the default that is returned in python but the text that is shown in the searchbox? So setting something like the initial search term?

Exactly, yes. Anytime the box is blank, use this default search term.

My use case here is a folder search combobox. When the box is blank, I want it to show all files in a folder. I don't want users to have to type "." to see everything.

m-wrzr commented 2 months ago

Could you also use default_options for this? Like:

result = st_searchbox(
    search, 
    default="default_folder_return",
    default_options=["your", "list", "of", "folders"],
)
hoggatt commented 2 months ago

The problem with this is that it won't actively run the search again, which may change over time.

Also, that wasn't working for me when I clear the result.

m-wrzr commented 2 months ago

I see the issue, just hesitant to add an additional argument that might be covered by already existing ones & the state updates having changed somewhat since the fork you linked above..

Can you maybe check if this https://github.com/m-wrzr/streamlit-searchbox/pull/61 would cover the usecase? this resets the searchbox while also updating the default_options when using clear_on_submit = True

pip install -i https://test.pypi.org/simple/ streamlit-searchbox==0.1.17a

hoggatt commented 2 months ago

Works perfectly! Thanks for helping with all my issues. This component is excellent and VERY usable for extreme use-cases. I might have one more low-priority minor feature request ;)