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

[TablePaginationActions]: Add ability to add a component between the left navigation and right navigation in TablePaginationActions. #43409

Open
nainshinayan opened this issue Aug 22, 2024 · 2 comments
Labels
component: TablePagination The React component. customization: slot Component's slot customizability enhancement This is not a bug, nor a new feature

Comments

@nainshinayan
Copy link

nainshinayan commented Aug 22, 2024

Summary

The default ActionsComponent for TablePagination is TablePaginationActions which renders the page navigation buttons. If TablePaginationActions can accept a custom component as a prop to render between the left navigation and right navigation, TablePaginationActions can be used to create a custom Action Component.

Examples

Screen Shot 2024-08-22 at 1 08 06 PM

Motivation

We have a design to add a TextField between the Left Navigation and Right Navigation to enter the page number.
Currently, there is no way to add this TextField component in TablePaginationActions. We have to fork the TablePaginationActions component and add the TextField.
If MUI can provide a prop to add a component between the left navigation and right navigation in TablePaginationActions, we can avoid the fork.

Search keywords: TablePaginationActions

@nainshinayan nainshinayan added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 22, 2024
@siriwatknp siriwatknp added component: TablePagination The React component. customization: css Design CSS customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 23, 2024
@siriwatknp
Copy link
Member

Thanks for reporting the issue! we will try to improve it in v7.

One idea that I can think of is accepting a children prop:

<TablePaginationActions>
  <TextField />
</TablePaginationActions>

@siriwatknp siriwatknp added enhancement This is not a bug, nor a new feature v7.x customization: slot Component's slot customizability and removed customization: css Design CSS customizability labels Aug 23, 2024
@nainshinayan
Copy link
Author

Thanks for the response siriwatknp this looks like a good solution but the solution is specific to my use case. If the user wants to place the TextField before the FirstButton, this solution will not work.

Suggestion: MUI can export the FirstButtonSlot, PreviousButtonSlot, NextButtonSlot, and LastButtonSlot and user can import these to use as per their requirement.

The below example is a possible use case where the user would want to position the navigation buttons differently.

import {FirstButtonSlot, PreviousButtonSlot, NextButtonSlot, LastButtonSlot } from '@mui/material/TablePagination';
import {Box} from '@mui/material/Box';
import {TextField} from '@mui/material/TextField';
import {Typography} from '@mui/material/Typography';



const CustomActionsComponent = ({showFirstButton, showLastButton, ...rest})=>{
     /**
      * States, context, and other logic will go here
      */

     return(
          <Box>
               <Typography>"Enter the page number"<Typography/>
               <TextField onChange={onChange} onKeyDown={onKeyDown} value={page} />
               <Typography>"Navigate to first and last page"<Typography/>
               <FirstButtonSlot {...rest}/>
               <LastButtonSlot {...rest}/>
               <Typography>"Navigate between pages"<Typography/>
               <PreviousButtonSlot {...rest}/>
               <NextButtonSlot {...rest}/>
          </Box>
     )
}

With this suggested solution to export the navigation buttons, if the user does not pass the custom ActionsComponent, MUI ActionComponents will be rendered. If the user wants a custom ActionsComponent, the user can import these navigation components and build their own and avoid all the forking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: TablePagination The React component. customization: slot Component's slot customizability enhancement This is not a bug, nor a new feature
Projects
None yet
Development

No branches or pull requests

3 participants