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.

Theme palette action selected color is not working in MUI version 5

See original GitHub issue

When creating a custom theme, the palette.action.select color property is not working. The other action color properties are working great.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

The select color on a dropdown select component is not working.

The default theme color is used instead.

Expected Behavior 🤔

The color on a selected dropdown menu item should be set.

Steps to Reproduce 🕹

See this code sample: https://codesandbox.io/s/palette-select-demo2-6ql8p?file=/src/Demo.tsx

import * as React from "react";
import { Box,InputLabel, MenuItem, FormControl, Select } from "@material-ui/core";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { red } from "@mui/material/colors";

const theme = createTheme({
  palette: {
    action: {
      select: red[500],
    },
  },
});

export default function Demo() {
  const [age, setAge] = React.useState('');

  const handleChange = (event) => {
    setAge(event.target.value);
  };

  return (
    <ThemeProvider theme={theme}>
      <Box sx={{ minWidth: 120 }}>
      <FormControl fullWidth>
        <InputLabel id="demo-simple-select-label">Age</InputLabel>
        <Select
          labelId="demo-simple-select-label"
          id="demo-simple-select"
          value={age}
          label="Age"
          onChange={handleChange}
        >
          <MenuItem value={10}>Ten</MenuItem>
          <MenuItem value={20}>Twenty</MenuItem>
          <MenuItem value={30}>Thirty</MenuItem>
        </Select>
      </FormControl>
    </Box>
    </ThemeProvider>
  );
}

Your Environment 🌎

Edge and Chrome browsers on Windows 10.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
bryanlopez-ibottacommented, Apr 7, 2022

I am trying to adjust theme.palette.action.selectedOpacity and theme.palette.action.hoverOpacity but it seems hit or miss… For example, it affects Buttons with variant secondary but not primary? It also seems to have different effects if I set the primary color in main versus light or dark. What is theme.vars

'&:hover': _extends({
  textDecoration: 'none',
  backgroundColor: theme.vars ? `rgba(${theme.vars.palette.text.primaryChannel} / ${theme.vars.palette.action.hoverOpacity})` : alpha(theme.palette.text.primary, theme.palette.action.hoverOpacity),
  // Reset on touch devices, it doesn't add specificity
  '@media (hover: none)': {
    backgroundColor: 'transparent'
  }
},
1reaction
ctbeisercommented, Mar 23, 2022

This is clearly a regression. MUI should be usable for design systems other than material, including ones that use secondary colors on list items.

At a minimum, it’s obviously wrong that there’s an item that can be specfied (selected) that changes nothing at all about the appearance of the theme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Palette - Material UI - MUI
The palette enables you to modify the color of the components to suit your brand. Palette colors. The theme exposes the following palette...
Read more >
MUI component received wrong theme color through SX ...
I just migrated my material UI version from 4 to 5. Everything went well, but now I have this strange bug: Everywhere else...
Read more >
Theming with React and MUI - Welcome, Developer
Learn how to create custom themes to React app using MUI. ... is to add a couple of buttons to the page so...
Read more >
Extend Material-UI theme in TypeScript - In Plain English
The problem of Material-UI theme; Extend Material-UI theme in TypeScript; Implement ... You normally assign one color to one palette option.
Read more >
MUI Themes Fully-Featured with MUI v5 - NetworkSynapse
Since MUI v5, themes provide lots of new possibilities. We look at many new ways to ... Lastly, our action object handles all...
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