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

[material-ui] Improve slot.transition and TransitionProps types #40650

Open
DiegoAndai opened this issue Jan 17, 2024 · 1 comment
Open

[material-ui] Improve slot.transition and TransitionProps types #40650

DiegoAndai opened this issue Jan 17, 2024 · 1 comment
Labels
breaking change component: transitions This is the name of the generic UI component, not the React module! customization: slot Component's slot customizability enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material typescript

Comments

@DiegoAndai
Copy link
Member

DiegoAndai commented Jan 17, 2024

The TransitionProps is based on the type with the same name coming from react-transition-group/Transition. The children prop is optional. There are a bunch of places where we do this to make children required:

TransitionProps & { children: React.ReactElement<any, any> }
User Image

We should standardize how we treat children in TransitionProps across the codebase. Potential solutions that can be explored:

  • Make children required in TransitionProps (material-ui).
  • Update transition components and make children optional in all of them.

Other things to consider:

  • Some slots.transition props (Accordion, Backdrop, SpeedDial) have the following type:

    transition?: React.JSXElementConstructor<
      TransitionProps & { children?: React.ReactElement<any, any> }
    >;
    

    The correct type should probably be:

    transition?: React.ElementType<TransitionProps>;
    
  • Improving the types should fix this issue in an Accordion demo: [material-ui][docs] Revise the Accordion page #40284 (comment)

Search keywords: slots transition typescript

@DiegoAndai DiegoAndai added typescript component: accordion This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material enhancement This is not a bug, nor a new feature labels Jan 17, 2024
@DiegoAndai DiegoAndai added this to the Material UI: v6 milestone Jan 17, 2024
@DiegoAndai DiegoAndai self-assigned this Jan 17, 2024
@DiegoAndai DiegoAndai moved this to Backlog in Material UI Mar 19, 2024
@DiegoAndai DiegoAndai removed their assignment Mar 19, 2024
@aarongarciah aarongarciah self-assigned this Jul 18, 2024
@aarongarciah aarongarciah moved this from Backlog to Selected in Material UI Jul 18, 2024
@aarongarciah aarongarciah moved this from Selected to In progress in Material UI Jul 19, 2024
@aarongarciah aarongarciah changed the title [material-ui][Accordion] Improve slots.transition type [material-ui] Improve TransitionProps type Jul 22, 2024
@aarongarciah aarongarciah added component: transitions This is the name of the generic UI component, not the React module! and removed component: accordion This is the name of the generic UI component, not the React module! labels Jul 22, 2024
@aarongarciah aarongarciah removed their assignment Jul 22, 2024
@aarongarciah aarongarciah moved this from In progress to Backlog in Material UI Jul 22, 2024
@aarongarciah aarongarciah removed this from the Material UI: v6 milestone Jul 22, 2024
@aarongarciah aarongarciah changed the title [material-ui] Improve TransitionProps type [material-ui] Improve slot.transition and TransitionProps types Jul 22, 2024
@hayzey
Copy link

hayzey commented Aug 22, 2024

Props specific to a certain transition type are also not recognised by default. For example...

Has error ❌

direction isn't recognised as a prop, because it's specific to Slide.

import Slide from '@mui/material/Slide';

function SnackbarComponent() {
  return (
    <Snackbar
      open={true}
      message={'Hello world!'}
      TransitionComponent={Slide}
      TransitionProps={{
        direction: 'right',
      }}
    />
  );
}

This works ✅

import Slide, { type SlideProps } from '@mui/material/Slide';

function SnackbarComponent() {
  return (
    <Snackbar
      open={true}
      message={'Hello world!'}
      TransitionComponent={Slide}
      TransitionProps={
        {
          direction: 'right',
        } as SlideProps
      }
    />
  );
}

@DiegoAndai DiegoAndai added the customization: slot Component's slot customizability label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: transitions This is the name of the generic UI component, not the React module! customization: slot Component's slot customizability enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material typescript
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

3 participants