Skip to content

Add clear filters action#22

Open
punitarani wants to merge 2 commits intomainfrom
feature/clear-all-filters-button
Open

Add clear filters action#22
punitarani wants to merge 2 commits intomainfrom
feature/clear-all-filters-button

Conversation

@punitarani
Copy link
Copy Markdown
Owner

No description provided.

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
flights-tracker Ready Ready Preview Comment Oct 9, 2025 11:50pm

@punitarani punitarani changed the title feat: add clear filters action Add clear filters action Oct 9, 2025
punitarani added a commit that referenced this pull request Oct 10, 2025
The clear filters button was triggering the airline dropdown to open
because handleAirlineClearSearch() focuses the input field, which in
turn triggers the onFocus handler that opens the dropdown.

Changed handleResetAllFilters to directly call setAirlineSearch("")
instead of handleAirlineClearSearch(), avoiding the unwanted focus
behavior while still clearing the search text.

Fixes the issue reported in PR #22.
punitarani added a commit that referenced this pull request Oct 10, 2025
Root cause: The Command component's onFocus handler opens the dropdown
whenever any element inside gets focus. Even though the previous fix
removed the explicit focus() call, React state updates and event
handling could still cause the dropdown to open during the reset.

Solution: Explicitly close the dropdown by calling
setIsAirlinePickerOpen(false) at the start of handleResetAllFilters.
This ensures the dropdown stays closed regardless of any subsequent
focus events or state updates during the reset process.

Also changed to call setAirlineSearch("") directly instead of
handleAirlineClearSearch() to avoid the focus() side effect.

Fixes the issue reported in PR #22.
punitarani added a commit that referenced this pull request Oct 11, 2025
Root cause: When the Clear Filters button is clicked and filters are reset,
the button becomes disabled (because canClearFilters becomes false). The
browser then automatically shifts focus to the next focusable element, which
can be the Command input, triggering the onFocus handler that opens the
dropdown.

Solution:
1. Add isResettingRef flag to track when a reset is in progress
2. Modify handleAirlineFocus to check !isResettingRef.current before opening
3. In handleResetAllFilters:
   - Set isResettingRef.current = true
   - Close dropdown with setIsAirlinePickerOpen(false)
   - Blur the input with commandInputRef.current?.blur()
   - Call onReset() and setAirlineSearch("")
   - Clear flag after 100ms timeout to allow focus events to settle

This prevents the focus handler from reopening the dropdown during the
reset process, regardless of browser focus management or React state
batching.

Fixes the issue reported in PR #22.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant