Skip to content

feat(defaultActive): set correct filter after clicking on clear#642

Open
karelhala wants to merge 1 commit into
patternfly:mainfrom
karelhala:default-active
Open

feat(defaultActive): set correct filter after clicking on clear#642
karelhala wants to merge 1 commit into
patternfly:mainfrom
karelhala:default-active

Conversation

@karelhala
Copy link
Copy Markdown
Collaborator

Description

When user clicks on clear filters the previously selected filter remains selected. This is unintuitive as we are basically clearing the whole filter section. This PR fixes it by activating first filter in the list. There's also an option to provide default filter which will be used when consumer provides it and user clears the filters.

Fixes 513

@karelhala karelhala requested a review from nicolethoen April 29, 2026 12:51
Copy link
Copy Markdown
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

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

This might benefit from one additional unit test that there is no issue if an invalid defaultActiveFilter is provided.


useEffect(() => {
setActiveAttributeMenu(getDefaultTitle());
}, [ filterItems, getDefaultTitle ]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This useEffect will reset the active filter anytime filterItems changes. If consumers are passing dynamic children (e.g., showing/hiding
filters based on permissions or feature flags), the user's manual filter selection gets reset even if their currently selected filter is still in
the list.

For example:

<DataViewFilters>
  <DataViewTextFilter filterId="name" title="Name" />
  {showAdvanced && <DataViewTextFilter filterId="location" title="Location" />}
</DataViewFilters>

User selects "Name" → toggles advanced filters → filterItems changes → resets back to default filter.

Consider moving this to mount-only or using an initialization flag so it doesn't fire on every children update.

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.

DataViewFilters dropdown: Reset active attribute to first item after the filters are cleared

2 participants