Skip to content

Conversation

@youknowriad
Copy link
Contributor

What?

Closes #71773

This PR exposes the FiltersToggled subcomponent to enable more flexible composition of DataViews filters interfaces. The component conditionally renders filters when isShowingFilter is true, allowing developers to position filters in custom layouts. It works in coordination with FiltersToggle component. One component sets the state and the other one uses it.

I kept the exiting Filters exposed for advanced layouts without toggle.

Testing Instructions

  1. Run Storybook: npm run storybook:dev
  2. Navigate to DataViews/DataViews
  3. Test the FreeComposition story:
    • Click the "Toggle Filters" button to show/hide filters
    • Verify that FiltersToggled component appears/disappears in the custom layout
    • Test filtering functionality by applying different filters
  4. Verify the component integrates properly in the custom header layout alongside other subcomponents

@youknowriad youknowriad self-assigned this Sep 25, 2025
@youknowriad youknowriad added the [Type] Enhancement A suggestion for improvement. label Sep 25, 2025
@github-actions
Copy link

github-actions bot commented Sep 25, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: priethor <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: johnhooks <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@@ -0,0 +1,73 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just noting that all these files are not new, this is just the exact same previous components that were defined in a single file, I split them into dedicated files for clarity.

Copy link
Contributor

@priethor priethor left a comment

Choose a reason for hiding this comment

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

Works as expected and implementation LGTM

Comment on lines +13 to +17
const { isShowingFilter } = useContext( DataViewsContext );
if ( ! isShowingFilter ) {
return null;
}
return <Filters { ...props } />;
Copy link
Member

Choose a reason for hiding this comment

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

So, the relevant change in this PR (other than splitting files) is creating this FilterToggled component, that handles the filters visibility without having to expose the DataViews context to the consumer. Is that correct?

Can we update the Filters component instead to handle this? When is it useful having a Filters component that doesn't handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we update the Filters component instead to handle this?

No we shouldn't because if you want to say render the "Filters" in a sidebar in your own implementation of DataViews, you can't use this with FiltersToggled, FiltersToggled is meant to be used in conjunction with FiltersToggle. The only other alternative is to actually remove FiltersToggle and let users implement it adhoc. I thought it's a nice shortcut for now, so I kept it.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Though In that case, consumers need to create their own "toogle" because FiltersToggle will respond to clicking by changing its style from "pressed" to "not pressed", but the filters will still be visible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly, and FitltersToggle is already exposed btw, and it just doesn't work on its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In other words, either you use both together (FiltersToggle and FiltersToggled) or you don't use any (Filters)

@youknowriad youknowriad merged commit a4959dc into trunk Sep 26, 2025
89 of 91 checks passed
@youknowriad youknowriad deleted the update/dataviews-expose-filters-toggled branch September 26, 2025 11:06
@github-actions github-actions bot added this to the Gutenberg 21.8 milestone Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataViews: Export DataViewsContext to enable custom layouts with individual components

4 participants