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

fix: search and filter panel no longer opens when dismissing a filter #1093

Merged

Conversation

jmuzina
Copy link
Member

@jmuzina jmuzina commented May 23, 2024

Done

Fixes the search & filter component re-opening the filter panel when removing a filter. The component will now behave as it does in the behaviour spec

The problem

The search & filter component has an on-click handler that opens the filter panel. This is currently being triggered by any clicks within the search and filter element and its descendants. This means that when a user clicks a chip dismissal button, the event bubbles up to the search & filter component & shows the filter panel.

Proposed solution

  1. Added the dismissal event to the parameter list of the Chip component's onDismiss callback.
  2. Call event.stopPropagation in the onDismiss callback passed into the filter chips by the search & filter component

Another possible solution

I initially tried another solution that removed the onClick handler from the search and filter component and moved it to the onFocus callback of the search input textbox. This also solves the issue, however it loses some functionality as clicking anywhere in the search and filter no longer opens the filter panel, and the only way to open the filter panel when it is overflowed is to click the CTA. So, I abandoned this approach for the approach in this PR.

Storybook

To see rendered examples of all react-components, run:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

QA steps

  1. Open Search & Filter component
  2. Click the component to open the filter panel.
  3. Add several filters.
  4. Close the filter panel by clicking outside of the component.
  5. Dismiss a filter by clicking its "x" button.
  6. Observe that the filter has been removed and the filter panel is still closed.

Percy steps

  • No visual changes expected

Fixes

Fixes: #621

@webteam-app
Copy link

@jmuzina jmuzina marked this pull request as ready for review May 23, 2024 18:45
Copy link

@pastelcyborg pastelcyborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think stopPropagation works well here - LGTM unless @bartaz has other thoughts.

@advl
Copy link
Contributor

advl commented Sep 11, 2024

LGTM, thank you !

Copy link
Member

@dgtlntv dgtlntv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@jmuzina jmuzina merged commit c4804ea into canonical:main Sep 12, 2024
18 checks passed
@jmuzina jmuzina deleted the fix-search-and-filter-open-on-remove-filter branch September 12, 2024 13:20
Copy link

🎉 This PR is included in version 1.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@edlerd
Copy link
Contributor

edlerd commented Sep 12, 2024

Wow, this has been around for a long time. Great improvement, I like it 👍

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

Successfully merging this pull request may close these issues.

Filter panel opens when a chip is removed
7 participants