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

[DataGrid] Update Quick Filter component to be expandable #16862

Merged
merged 35 commits into from
Mar 24, 2025

Conversation

KenanYusuf
Copy link
Member

@KenanYusuf KenanYusuf commented Mar 7, 2025

This PR updates the Quick Filter component, allowing it to be expandable/collapsable via the new <QuickFilterTrigger />. Also included:

  • Documented the new component
  • Added docs examples to demonstrate the new expand/collapse behavior
  • Updated the default toolbar to be collapsed by default

Closes #17027.

Default toolbar example

Quick Filter component docs

With mouse

mouse-navigation.mp4

With keyboard

keyboard-navigation.mp4

@KenanYusuf KenanYusuf added component: data grid This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer enhancement This is not a bug, nor a new feature labels Mar 7, 2025
@KenanYusuf KenanYusuf changed the title [DataGrid] Collapse Quick Filter when not in use [DataGrid] Expandable/collapsible quick filter Mar 18, 2025
@KenanYusuf KenanYusuf added feature: Filtering Related to the data grid Filtering feature feature: Toolbar Related to the data grid Toolbar feature labels Mar 18, 2025
Copy link

Thanks for adding a type label to the PR! 👍

@@ -1,6 +1,6 @@
import * as React from 'react';
Copy link
Member Author

@KenanYusuf KenanYusuf Mar 20, 2025

Choose a reason for hiding this comment

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

Will add tests for the new toolbar, including the roving tabindex functionality, in a follow-up PR to avoid this one growing any more.

@KenanYusuf KenanYusuf changed the title [DataGrid] Expandable/collapsible quick filter [DataGrid] Update Quick Filter component to be expandable Mar 20, 2025
@KenanYusuf KenanYusuf marked this pull request as ready for review March 20, 2025 16:11
@KenanYusuf KenanYusuf requested a review from a team March 20, 2025 16:11
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the component set its state to expanded if the input is focused through other means? In this example, I focus it using the vimium browser extension. It's nice to be able to start typing into it without having to touch the mouse.

Screencast.From.2025-03-20.13-14-36.mp4

Copy link
Member Author

@KenanYusuf KenanYusuf Mar 21, 2025

Choose a reason for hiding this comment

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

That's a fun extension 👌

Updated to support that behavior b6b1db2

Copy link
Contributor

@romgrk romgrk Mar 21, 2025

Choose a reason for hiding this comment

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

On a similar note, UX wise this would feel better, imo: instead of adding the "Search" button to the tabIndex order, just leave the input in the tabIndex order so that when a user tabs into that component, it expands without the need for an additional button click. I would expand it directly as soon as there is focus though, not only in the next onChange event like your commit does.

And then tabbing out of it would still blur it (if empty) like it already does.

The "Search" button can stay with tabIndex=-1 for mouse/touch users.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the suggestion. The other consideration here is that the quick filter input could (and probably should) also be part of the "roving tabindex" like the toolbar buttons. I'm thinking of implementing similar behavior to the Base UI ToolbarInput which you can see in this video: https://x.com/colmtuite/status/1902766567256907880. Added both to my master toolbar follow-up issue to consider #16864


### Expand quick filter via keyboard

The demo below shows how to control the quick filter state using the `expanded` and `onExpandedChange` props to support expanding the quick filter via keyboard. Try pressing <kbd class="key">Cmd</kbd> (or <kbd class="key">Ctrl</kbd> on Windows)+<kbd class="key">Shift</kbd>+<kbd class="key">P</kbd>.
Copy link
Member

Choose a reason for hiding this comment

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

Firefox, Brave, and perhaps other browsers use the Cmd+Shift+P shortcut, so we either add event.preventDefault() or use a different shortcut.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it to just CMD+P and added event.preventDefault() when the grid is focused—avoids it hijacking native/browser shortcuts for the rest of the page.

}
};

window.addEventListener('keydown', handleKeyDown);
Copy link
Member

Choose a reason for hiding this comment

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

Attaching the handler to the window only makes sense if the data grid is the main widget on the page.
Assuming people will be copying the code to their projects, I think it's better to attach it to the grid root element so that it only works if the data grid has focus.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I've updated it to use the root element 4206792

@KenanYusuf KenanYusuf merged commit 8297fab into mui:master Mar 24, 2025
22 checks passed
@KenanYusuf KenanYusuf deleted the expandable-quick-filter branch March 24, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer enhancement This is not a bug, nor a new feature feature: Filtering Related to the data grid Filtering feature feature: Toolbar Related to the data grid Toolbar feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[data grid] Expandable/collapsible quick filter
4 participants