Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The searchTerm in the searchPredicate function is never an empty string #637

Closed
lennertVanSever opened this issue Jul 12, 2023 · 7 comments
Labels

Comments

@lennertVanSever
Copy link

Describe the bug
When a user types in the input field, the searchPredicate function is triggered with whatever the user is writing. However, when the user empties his input field, the searchPredicate function is never triggered with an empty string.

To Reproduce

function searchPredicate(node, searchTerm) {
  console.log(searchTerm) // this is never an empty string ""
  return false
}

return <DropdownTreeSelect data={data} searchPredicate={searchPredicate} />

Expected behavior
When the input field is emptied, the searchPredicate function is triggered with an empty string.

@gandhis1
Copy link
Contributor

Is an empty string a valid search term? What use case do you anticipate for this?

I made a specific change that was accepted a few months ago to do this because there did not appear to be a good reason to incur the search predicate cost across a potentially large number of nodes with an empty string. See #580

@lennertVanSever
Copy link
Author

In my project, we use the searchPredicate function to build a custom async tree dropdown. Now our component is not working as expected when the input is cleared, we should be able to show all the options in that case but we can't.

@gandhis1
Copy link
Contributor

In my project, we use the searchPredicate function to build a custom async tree dropdown. Now our component is not working as expected when the input is cleared, we should be able to show all the options in that case but we can't.

So the change I had made would not filter anything if search mode was off, which it was if the query was an empty string. That is, I would expect the default behavior with an empty string is to show all options.

Is this something you can create a code sandbox demonstrating?

@lennertVanSever
Copy link
Author

Hi, I have a sandbox here with an example: https://codesandbox.io/s/blue-snowflake-jqt35v?file=/src/index.js

if the search term is empty, it is not reflected that way in the searchPredicate

@mrchief
Copy link
Collaborator

mrchief commented Jul 21, 2023

searchPredicate was meant to return matches, so an empty string doesn't mean it matches all. That can be a business interpretation for a particular use case but baking that in, makes the control opinionated.

I like the idea of a separate function to notify when the search input is empty but I wonder why there are so many changed files. We need to verify if every snapshot is still the same, which at a glance appears to be so but again, I don't like the fact that avajs decided to change the render sequence throwing the git diff off.

@lennertVanSever
Copy link
Author

Thanks for your response @mrchief. The many file changes are indeed related to the avajs. I only executed ava --update-snapshots so no idea what went wrong on that regard.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants