material-ui-search-bar icon indicating copy to clipboard operation
material-ui-search-bar copied to clipboard

FEATURE REQUEST: Give option to NOT clear the search when canceling search.

Open tazbill opened this issue 4 years ago • 2 comments

This originally came from me trying to override the cancel functionality all together.

<SearchBar
	value={searchText}
	onChange={handleSearchTextChanged}
	closeIcon={<SearchIcon style={{ color: grey[500] }} />}
	onRequestSearch={performSearch}
	onCancelSearch={performSearch}
/>

This SHOULD have allowed me to keep the search icon visible and allow the user to click it when they wanted to search without worrying about knowing to hit enter.

However, the setValue('') is the first line called in the cancel method regardless of whether or not we have custom functions.

I propose adding a new property cancelClearsText or something far less ridiculous than that. Then in the cancel method, check for this property before clearing the search text.

In the meantime, I'm just going to REset the search text after a cancel and will have to wrap the performSearch in a cancel handler

tazbill avatar Jun 16 '21 16:06 tazbill

This would also solve the issue raised in #86

tazbill avatar Jun 16 '21 16:06 tazbill

@tazbill instead of a new property what if the check was for the onRequestSearch function and if that function existed then the search button wouldn't be replaced by the clear button.

I'm thinking this would look like:

<SearchBar
	value={searchText}
	onRequestSearch={performSearch}
/>

https://user-images.githubusercontent.com/46388252/127773034-cb770db4-fe17-4a8a-96a3-dcf316535cf0.mov

What are your thoughts?

SnekCode avatar Aug 01 '21 13:08 SnekCode