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] Refactor: create base Pagination #16759

Merged
merged 16 commits into from
Mar 11, 2025

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Feb 27, 2025

Part of the design-system agnostic work.

@romgrk romgrk added the component: data grid This is the name of the generic UI component, not the React module! label Feb 27, 2025
@romgrk romgrk requested a review from a team February 27, 2025 22:36
Comment on lines 192 to 199
getItemAriaLabel?: (type: 'first' | 'last' | 'next' | 'previous') => string;
labelRowsPerPage?: string;
labelDisplayedRows?: (info: {
from: number;
to: number;
count: number;
page: number;
}) => React.ReactNode | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having this here is ugly, but I don't see how to avoid 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.

Tbd: move pagination locales from the core to here.

Copy link
Member

Choose a reason for hiding this comment

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

Having this here is ugly, but I don't see how to avoid it.

Alternatively, we can use apiRef.current.getLocaleText() instead of passing the prop.
But passing a prop looks good to me too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've handled l10n in the material bindings, other design-systems can easily fork that code and it removes l10n props from the typings.

@mui-bot
Copy link

mui-bot commented Feb 27, 2025

Localization writing tips ✍️

Seems you are updating localization 🌍 files.

Thank you for contributing to the localization! 🎉 To make your PR perfect, here is a list of elements to check: ✔️

  • Verify if the PR title respects the release format. Here are two examples (depending if you update or add a locale file)

    [l10n] Improve Swedish (sv-SE) locale
    [l10n] Add Danish (da-DK) locale

  • Update the documentation of supported locales by running pnpm l10n
  • Clean files with pnpm prettier.

Deploy preview: https://deploy-preview-16759--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against c60bb4e

{...locales}
labelDisplayedRows={wrappedLabelDisplayedRows}
{...props}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had to remove ...props in some places and it makes it imposible for users to use e.g. rootProps.slotProps.pagination to customize the slot, but we can't both be design-system agnostic and pass any material-ui prop.

The solution here would be for users to fork the basePagination slot and customize it there.

Copy link
Member

Choose a reason for hiding this comment

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

I've had to remove ...props in some places and it makes it imposible for users to use e.g. rootProps.slotProps.pagination to customize the slot

Why though? What is different about the Pagination slot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant: it's not going to be possible to pass material props via slotProps.pagination.

Copy link
Member

Choose a reason for hiding this comment

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

I meant: it's not going to be possible to pass material props via slotProps.pagination.

Ahh, only via slotProps.basePagination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that base slots are not material slots anymore, they're design-system agnostic. For some of them, it might happen that the grid's base slot API matches the material API, but it's not consistent. I have been thinking about adding something like slotProps.raw to all base components to pass custom props to the underlying design-system, be it material or something else.

{...locales}
labelDisplayedRows={wrappedLabelDisplayedRows}
{...props}
Copy link
Member

Choose a reason for hiding this comment

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

I've had to remove ...props in some places and it makes it imposible for users to use e.g. rootProps.slotProps.pagination to customize the slot

Why though? What is different about the Pagination slot?

* The custom Pagination component used in the grid.
* @default Pagination
*/
basePagination: React.JSXElementConstructor<GridSlotProps['basePagination']>;
Copy link
Member

Choose a reason for hiding this comment

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

Why rename the slot?
Regarding the base prefix, we seem to only prefix "primitive" components used in multiple places.
Pagination is a one-off component that is closer to the filter panel than to a "primitive" component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't use @mui/material/TablePagination in the core. If we still want to use it in the material grid, we need it as a base component. The alternative would be to re-implement the pagination in the core grid using the available base components (button, select, etc).

Copy link
Member

Choose a reason for hiding this comment

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

OK, so the base prefix now means "design-agnostic slot", correct?

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 11, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 11, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 11, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 11, 2025
@romgrk romgrk merged commit ef26339 into mui:master Mar 11, 2025
18 checks passed
@romgrk romgrk deleted the refactor-agnostic-pagination branch March 11, 2025 19:12
@michelengelen
Copy link
Member

@romgrk shouldn't we spread the slotProps onto the basePagination as well to allow for slots overrides?

--- a/packages/x-data-grid/src/components/GridPagination.tsx
+++ b/packages/x-data-grid/src/components/GridPagination.tsx
@@ -102,6 +102,7 @@ function GridPagination() {
       onPageChange={handlePageChange}
       onRowsPerPageChange={handlePageSizeChange as any}
       disabled={disabled}
+      {...(rootProps.slotProps?.basePagination ?? {})}
     />
   );
 }

This is regarding issue #17045

cc @cherniavskii

@romgrk
Copy link
Contributor Author

romgrk commented Mar 21, 2025

That would not solve the user's issue. They're trying to pass material-ui props to a grid base component which has a different set of props. We might want to introduce slotProps.native to pass props to the underlying design-system.

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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants