Modifying Dashboard search clear button to clear all search params.

This commit is contained in:
Roland 2024-05-25 10:48:08 -06:00
parent bd8411bcd7
commit dd13534a39
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
7 changed files with 43 additions and 11 deletions

View file

@ -400,7 +400,7 @@ export function scrollToTopOfElement(element, smooth = true) {
});
}
const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small', placeholder = 'Search...', icon = 'search') => {
const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small', placeholder = 'Search...', icon = 'search', clearDisabled = null) => {
const [value, setValue] = useState(searchStr || '');
const [submitted, setSubmitted] = useState(false);
@ -459,7 +459,9 @@ const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small
size={size}
onClick={handleClearSearch}
type='button'
disabled={!!!value}
// If `clearDisabled` is provided, use it to disable the clear button. Fallback to disabling if there is no
// search value.
disabled={clearDisabled !== null ? clearDisabled : !!!value}
className='search-clear'
/>;
@ -508,6 +510,7 @@ export function SearchResultsInput({
action,
actionIcon,
clearable = false,
clearDisabled = null,
autoFocus = false,
results = undefined,
handleResultSelect = null,
@ -521,7 +524,7 @@ export function SearchResultsInput({
clearButton,
localOnSubmit,
handleChange,
} = useClearableInput(searchStr, onChange, onClear, onSubmit, size, placeholder);
} = useClearableInput(searchStr, onChange, onClear, onSubmit, size, placeholder, icon, clearDisabled);
// Show a "Loading" message rather than "No results" while results are pending.
const loadingResults = {'loading': {name: 'Loading', results: [{title: 'Results are pending...'}]}};