question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[LoadingButton] defaultProps is no longer inherited from MuiButton defaultProps in @mui/lab 5.0.0-alpha.55 version

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

I had a theme with changed variant default prop value for MuiButton. The previous versions of @mui/lab applied this value for MuiLoadingButton components. Starting with version 5.0.0-alpha.55 it doesn’t work. Now we need also change default prop value for MuiLoadingButton separately.

Expected behavior 🤔

It should inherit default prop value from MuiButton as MuiLoadingButton component is based on Button and inherits all its props.

Steps to reproduce 🕹

createTheme

const theme = createTheme({
    components: {
        MuiButton: {
            defaultProps: {
                variant: 'contained',
            },
        },
        // MuiLoadingButton: {
        //     defaultProps: {
        //         variant: 'contained',
        //     },
        // },
    }
});

test component

<ThemeProvider theme={theme}>
    <LoadingButton>It should be contained</LoadingButton>
</ThemeProvider>

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 11.6.1
  Binaries:
    Node: 16.8.0 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 7.21.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 95.0.4638.69
    Edge: Not Found
    Firefox: 92.0
    Safari: 15.1
  npmPackages:
    @emotion/react: ^11.5.0 => 11.6.0 
    @emotion/styled: ^11.3.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.55 
    @mui/icons-material: ^5.0.4 => 5.1.1 
    @mui/lab: ^5.0.0-alpha.55 => 5.0.0-alpha.55 
    @mui/material: ^5.1.0 => 5.1.1 
    @mui/private-theming:  5.1.1 
    @mui/styled-engine:  5.1.1 
    @mui/system:  5.1.1 
    @mui/types:  7.1.0 
    @mui/utils:  5.1.1 
    @types/react: ^17.0.0 => 17.0.35 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    typescript: ^4.4.3 => 4.4.4 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
danderson00commented, Jul 12, 2022

Not sure why this is closed. Attempting to set MuiButton variant property using defaultProps does not seem to work, as of 5.8.7. Can we reopen, or should I open another issue?

1reaction
ZeeshanTambolicommented, May 26, 2022

Sorry to necro this closed issue, but given this change, how does one change the default props for a LoadingButton or other lab components?

I use this approach https://mui.com/material-ui/customization/theme-components/ for @mui/material components,

but if I add a @mui/lab component to the components object, I get a compiler error:

import type { ButtonProps, ThemeOptions } from '@mui/material'
import { createTheme } from '@mui/material'

const btnCommon: Partial<ButtonProps> = {
  variant: 'contained',
}

const themeOptions: ThemeOptions = {
  components: {
    MuiButton: {
      defaultProps: btnCommon,
    },
// TS error:
// Object literal may only specify known properties, and 'MuiLoadingButton' does not exist in type 'Components<BaseTheme>'.
    MuiLoadingButton: {  
      defaultProps: btnCommon,
    },
// ... other components
}

export const MuiOverrides = createTheme(themeOptions)

I tried using any type to allow me to pass MuiLoadingButton in that object, but it has no effect.

If you are using TypeScript, you need to import types by leveraging module augmentation. See: https://mui.com/material-ui/about-the-lab/#typescript

Read more comments on GitHub >

github_iconTop Results From Across the Web

LoadingButton API - Material UI - MUI
Rule name Global class Description root.MuiLoadingButton‑root Styles applied to the root element. fullWidth.MuiLoadingButton‑fullWidth Styles applied to the root element if fullWidth= . endIcon.MuiLoadingButton‑endIcon Styles applied to...
Read more >
@mui/lab | Yarn - Package Manager
This package hosts the incubator components that are not yet ready to move to core . Installation. Install the package in your project...
Read more >
Creating a defaultProps with createTheme in MUI v5 not working
I'm using Material-UI v5 for the first time, and I want to create a custom theme with createTheme to style a button component....
Read more >
CHANGELOG.md · Gitee 极速下载/Material-UI - Gitee.com
Versions. 5.10.7. Sep 26, 2022. A big thanks to the 21 contributors who made this release possible. Here are some highlights ✨:.
Read more >
node_modules/@mui/base/CHANGELOG.md · master · Daniel ...
This release was mostly around bug fixes and documentation improvements. ... @mui/lab@5.0.0-alpha.55. ​[LoadingButton] Text variant spacing fixed for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found