-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
getItemAriaLabel?: (type: 'first' | 'last' | 'next' | 'previous') => string; | ||
labelRowsPerPage?: string; | ||
labelDisplayedRows?: (info: { | ||
from: number; | ||
to: number; | ||
count: number; | ||
page: number; | ||
}) => React.ReactNode | undefined; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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: ✔️
Deploy preview: https://deploy-preview-16759--material-ui-x.netlify.app/ |
{...locales} | ||
labelDisplayedRows={wrappedLabelDisplayedRows} | ||
{...props} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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']>; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
@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 |
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 |
Part of the design-system agnostic work.