Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
Extending Material UI theme via Module Augmentation not working

I'm trying to add an "input" property to the background field within palette and then augment the Theme to account for types, like so:

export const lightTheme = createTheme(commonTheme, {
  palette: {
    mode: 'light',
    background: {
     default: '#FFFFFF',
     input: '#0000BB',
      ...
}
declare module '@mui/material/styles' {
  interface Theme {
    background: {
      input: React.CSSProperties['color'];
    };
  }

  interface ThemeOptions {
    background: {
      input: React.CSSProperties['color'];
    };
  }
}

However, when I try to access background via color: theme.palette.background.input, i get an error:

Property 'input' does not exist on type 'TypeBackground'.

Why is augmentation not adding the type to the background property?

To add, I also tried this which didn't change anything:

declare module "@mui/material/styles/createPalette" {
  interface CommonColors {
    background: {
      input: React.CSSProperties['color'];
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You just need to extend the type TypeBackground as shown below:

declare module '@mui/material/styles' {
   interface TypeBackground {
        input: string;
    }
}

and then configure a new value for background.input

const theme = createTheme({
  ....
  palette: {
    background: {
      input: "#f60"
    }
  }
 ...
});

Finally, we can use it like this:

<Box sx={{ bgcolor: "background.input", width: 100, height: 100 }} />

The demo link

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda