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

[Accordion] TransitionProps isn't merged with theme defaultProps #34978

Open
2 tasks done
ianschmitz opened this issue Nov 1, 2022 · 4 comments · May be fixed by #35088
Open
2 tasks done

[Accordion] TransitionProps isn't merged with theme defaultProps #34978

ianschmitz opened this issue Nov 1, 2022 · 4 comments · May be fixed by #35088
Labels
bug 🐛 Something doesn't work component: accordion This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features

Comments

@ianschmitz
Copy link
Contributor

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example: https://codesandbox.io/s/twilight-sun-nn4m8m?file=/src/App.tsx

Steps:

  1. Expand accordion 1 and observe console.log message
  2. Expand accordion 2 and observe there is no console.log

Current behavior 😯

TransitionProps objects aren't merged with defaultProps provided by the theme.

Expected behavior 🤔

TransitionProps objects are merged with defaultProps provided by the theme.

Context 🔦

I'm trying to provide transition defaults for the Accordion such as setting unmountOnExit or mountOnEnter globally, while allowing component level props such as timeout etc to be provided as well.

Your environment 🌎

npx @mui/envinfo
  System:
    OS: macOS 13.0
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.14.0/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Edge: Not Found
    Firefox: 106.0.2
    Safari: 16.1
  npmPackages:
    @emotion/react: ^11.10.0 => 11.10.0 
    @emotion/styled: ^11.10.0 => 11.10.0 
    @mui/base:  5.0.0-alpha.100 
    @mui/core-downloads-tracker:  5.10.8 
    @mui/icons-material: ^5.10.6 => 5.10.6 
    @mui/material: ^5.10.8 => 5.10.8 
    @mui/private-theming:  5.10.6 
    @mui/styled-engine:  5.10.8 
    @mui/system:  5.10.8 
    @mui/types:  7.2.0 
    @mui/utils:  5.10.6 
    @mui/x-data-grid:  5.17.5 
    @mui/x-data-grid-pro: ^5.17.5 => 5.17.5 
    @mui/x-date-pickers:  5.0.3 
    @mui/x-date-pickers-pro: ^5.0.3 => 5.0.3 
    @mui/x-license-pro:  5.17.0 
    @types/react: ^18.0.17 => 18.0.17 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
    typescript: ~4.8.4 => 4.8.4 
@ianschmitz ianschmitz added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 1, 2022
@zannager zannager added the component: accordion This is the name of the generic UI component, not the React module! label Nov 2, 2022
@hbjORbj hbjORbj self-assigned this Nov 3, 2022
@hbjORbj hbjORbj changed the title Accordion TransitionProps isn't merged with theme defaultProps [Accordion] TransitionProps isn't merged with theme defaultProps Nov 3, 2022
@flaviendelangle
Copy link
Member

flaviendelangle commented Nov 17, 2022

The topic is similar to #34214

@ianschmitz
Copy link
Contributor Author

Looks like you linked back to here @flaviendelangle

@flaviendelangle
Copy link
Member

Indeed, updated 👍

@ZeeshanTamboli ZeeshanTamboli added customization: theme Centered around the theming features and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 19, 2022
@ZeeshanTamboli ZeeshanTamboli added the bug 🐛 Something doesn't work label Dec 8, 2022
@oliviertassinari
Copy link
Member

oliviertassinari commented May 22, 2023

I'm not sure to understand how the "expected behavior" is correct. In the example,

import * as React from "react";
import {
  Accordion,
  AccordionDetails,
  AccordionSummary,
  createTheme,
  ThemeProvider,
  Typography
} from "@mui/material";

const theme = createTheme({
  components: {
    MuiAccordion: {
      defaultProps: {
        TransitionProps: {
          // Console log to demonstrate the bug
          onEnter: (el) => console.log("accordion el has expanded", el)
        }
      }
    }
  }
});

/**
 * how you used the components
 */
export default function App() {
  return (
    <ThemeProvider theme={theme}>
      <Accordion
        // Opening this accordion will console log as expected
        TransitionProps={undefined}
      >
        <AccordionSummary aria-controls="panel1a-content" id="panel1a-header">
          <Typography>Accordion 1</Typography>
        </AccordionSummary>
        <AccordionDetails>
          <Typography>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
            malesuada lacus ex, sit amet blandit leo lobortis eget.
          </Typography>
        </AccordionDetails>
      </Accordion>
      <Accordion
        // BUG: There will be no console log when opening this accordion.
        TransitionProps={{}}
      >

If I set TransitionProps={{}}, I would expect TransitionProps to be {}, I'm overriding the default prop, per https://mui.com/material-ui/customization/theme-components/#theme-default-props, so we could expect no console log.

For the same reason why when overriding Fade's timeout prop https://mui.com/material-ui/api/fade/, it erases the default prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: accordion This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants