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

Dropdown filter : Filter Field Resets to Empty String on Empty Filter Result when uing onFilterEvent to fetch options dynamically #6265

Closed
mohamadbdeir opened this issue Mar 30, 2024 · 4 comments · Fixed by #6270
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@mohamadbdeir
Copy link
Contributor

Describe the bug

When utilizing the Dropdown component with the onFilterEvent callback to fetch options dynamically from a backend API, an issue occurs where the filter field automatically resets to an empty string if the filtering operation results in an empty array.

Reproducer

No response

PrimeReact version

10.6.2

React version

18.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Implement a call to remote API to fetch Dropdown options by a field value
  2. Initialize a state variable that will hold the filter value
  3. Use onFilter event in Dropdown to set the filter variable to event.filter
  4. use useEffect to react to filter value change to fetch options
  5. type a filter value that returns no result and filter value will be reset to empty string

Expected behavior

The filter value should not be reset

@mohamadbdeir mohamadbdeir added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 30, 2024
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Mar 31, 2024
@gucal gucal added this to the 10.6.3 milestone Apr 9, 2024
@dingzhanjun
Copy link

I am on 10.7.0 and the reset still happens

@melloware
Copy link
Member

@dingzhanjun can you create a StackBlitz reproducer and open a new ticket if you can reproduce it?

@dingzhanjun
Copy link

dingzhanjun commented Jul 23, 2024

thanks for your response! it is really weird, I created a StackBlitz and it works, but it just does not work in my project, what could be the issue on earth? the only difference is I am using it with react-hook-form

@melloware
Copy link
Member

hmmm its possible RHF is messing it up? I wouldn't think so though unless the onChange or onBlur of RHF is messing it up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
4 participants