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] createTheme typography not working on extended Theme #10701

Closed
fdebef opened this issue Oct 17, 2023 · 2 comments
Closed

[DataGrid] createTheme typography not working on extended Theme #10701

fdebef opened this issue Oct 17, 2023 · 2 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: css Design CSS customizability status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it support: commercial Support request from paid users

Comments

@fdebef
Copy link
Contributor

fdebef commented Oct 17, 2023

The problem in depth 🔍

Quite simple situation:
I have simple DataGridPro table with default theme:

const theme = createTheme(
  {
    palette: {
      primary: { main: '#1976d2' },
    },
  },
  csCZ,
);

I want to extend this theme with simple typography font size:

  const theme = createTheme(defaultTheme, {
    typography: {
      fontSize: 8,
    },
  });

This does not affect the table inside ThemeProvider.
If I try modify the theme like this:

const theme = createTheme(defaultTheme, {
    typography: {
      fontSize: 8,
    },
    palette: {
      primary: { main: '#FF0000' },
    },
  });

then in the palette change works, the typography not. Here in live demo: https://codesandbox.io/embed/thirsty-mendel-rpmdk7

Your environment 🌎

`npx @mui/envinfo`
System:
    OS: macOS 14.0
  Binaries:
    Node: 20.1.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 9.6.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 118.0.5993.70
    Edge: Not Found
    Safari: 17.0
  npmPackages:
    @emotion/react: ^11.10.5 => 11.11.1 
    @emotion/styled: ^11.10.5 => 11.11.0 
    @mui/base:  5.0.0-beta.19 
    @mui/core-downloads-tracker:  5.14.13 
    @mui/icons-material: ^5.11.16 => 5.14.13 
    @mui/material: ^5.11.7 => 5.14.13 
    @mui/private-theming:  5.14.13 
    @mui/styled-engine:  5.14.13 
    @mui/system:  5.14.13 
    @mui/types:  7.2.6 
    @mui/utils:  5.14.13 
    @mui/x-data-grid:  6.16.2 
    @mui/x-data-grid-pro: ^6.16.2 => 6.16.2 
    @mui/x-license-pro:  6.10.2 
    @types/react:  18.2.28 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 

Search keywords: createTheme typography fontSize
Order ID: 57288

@fdebef fdebef added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Oct 17, 2023
@cherniavskii
Copy link
Member

Hey @fdebef
I believe this is the expected behavior:

Source: https://mui.com/material-ui/customization/theming/#api

Here's a fixed demo: https://codesandbox.io/s/unruffled-ardinghelli-gms9hz

@cherniavskii cherniavskii added component: data grid This is the name of the generic UI component, not the React module! status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it customization: css Design CSS customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 19, 2023
@cherniavskii cherniavskii closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
@fdebef
Copy link
Contributor Author

fdebef commented Oct 19, 2023

Hey, thanks for answering, but you're talking about merging two themes, but I want to merge Theme (as a result of createTheme) and options as described in documentation as "Theme composition" (though I agree, that the mention about processing only first argument can be found in same chapter - I am a bit confused).

Theme composition: using theme options to define other options
When the value for a theme option is dependent on another theme option, you should compose the theme in steps.

import { createTheme } from '@mui/material/styles';

let theme = createTheme({
  palette: {
    primary: {
      main: '#0052cc',
    },
    secondary: {
      main: '#edf2ff',
    },
  },
});

theme = createTheme(theme, {
  palette: {
    info: {
      main: theme.palette.secondary.main,
    },
  },
});

Think of creating a theme as a two-step composition process: first, you define the basic design options; then, you'll use these design options to compose other options.

Yet one question is, why it works for palette and not for typography.

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! customization: css Design CSS customizability status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it support: commercial Support request from paid users
Projects
None yet
Development

No branches or pull requests

2 participants