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

[SelectField] How to change/override "color" style of selected option of SelectField ? #3388

Closed
wzup opened this issue Feb 19, 2016 · 17 comments
Labels
component: select This is the name of the generic UI component, not the React module!

Comments

@wzup
Copy link

wzup commented Feb 19, 2016

I cannot override color style for selected option. It is always black:

element.style {
    color: rgba(0, 0, 0, 0.870588);  // <---
    line-height: 56px;
    opacity: 1;
    position: relative;
    padding-left: 0px;
    padding-right: 48px;
    top: 6px;
}

I have set all possible related style options and neither works.

                <SelectField
                    value={this.state.value}
                    onChange={this.onChange}
                    floatingLabelText={this.state.floatingLabelText}
                    floatingLabelStyle={{color: '#fff'}} // <--
                    underlineStyle={{display: 'none'}}
                    errorText={this.state.errorText}
                    selectFieldRoot={{color: "#fff"}} // <--
                    style={{color: "#fff"}} // <--
                    iconStyle={{color: "#fff"}} // <--
                >
                    {this.state.source}
                </SelectField>

How do you override color?

@wzup wzup changed the title How to change "color" style of selected option of SelectField ? How to change/override "color" style of selected option of SelectField ? Feb 19, 2016
@oliviertassinari
Copy link
Member

At this moment, you can only change the palette.accent1Color key. There is one style property on the Menu component for this: selectedMenuItemStyle, but that property is not accessible from the SelectField component.

@wzup
Copy link
Author

wzup commented Feb 19, 2016

palette.accent1Color is not a color of selected option. It is a text color of options inside list of options to choose from:

material-ui - google chrome 2016-02-20 00 27 16

And I'd like to change this color, a color of selected option. Set it color: #fff:
material-ui - google chrome 2016-02-20 00 29 54

I found that it is a textColor ( textColor: _colors2.default.darkBlack, ). I've created my theme:

import Colors from 'material-ui/lib/styles/colors';
import ColorManipulator from 'material-ui/lib/utils/color-manipulator';
import Spacing from 'material-ui/lib/styles/spacing';
import zIndex from 'material-ui/lib/styles/zIndex';

export default {
    spacing: Spacing,
    zIndex: zIndex,
    fontFamily: 'Roboto, sans-serif',
    palette: {
        textColor: Colors.white,
    }
};

But the problem now it that textColor is not only a color of selected option but also a color of options to choose from. So if I set it textColor: Colors.white, I cannot see options because of white layout of dropdown list:

google chrome 2016-02-20 00 46 15

How to change only the color of selected option, not of all options in the list of options?

@oliviertassinari
Copy link
Member

palette.accent1Color is not a color of selected option.

Sorry but yes it's. For instance, here, I'm using accent1Color = colors.green100
capture d ecran 2016-02-19 a 20 39 54

@wzup wzup changed the title How to change/override "color" style of selected option of SelectField ? [SelectField] How to change/override "color" style of selected option of SelectField ? Feb 20, 2016
@wzup
Copy link
Author

wzup commented Feb 20, 2016

Ok, I see.
How to override _only_ this color? without changing any other text colors. I need it to be white.

material-ui - google chrome 2016-02-20 10 34 11

@oliviertassinari
Copy link
Member

You can change the color of the selected text like this:

import getMuiTheme from 'material-ui/lib/styles/getMuiTheme';

const muiTheme = getMuiTheme({}, {
  menuItem: {
    selectedTextColor: 'white',
  },
});

But in your case, you want to change the color of the text field, use inputStyle.

@thomasmery
Copy link

Hi,

just found out about selectedMenuItemStyle not being passed down to the Menu in SelectField

is there a reason why this is not possible/implemented?

many thanks

@ishwinder
Copy link

@wzup were you able to get this going ?

@aaronboss
Copy link

aaronboss commented May 20, 2016

Did you try labelStyle?

<SelectField labelStyle={{ color: 'green' }} />

@samrocksc
Copy link

how do you get rid of the underline on these components....geeze louise.

@DoubleU23
Copy link

DoubleU23 commented Oct 12, 2016

as @thomasmery said:

just found out about selectedMenuItemStyle not being passed down to the Menu in SelectField

thats solved in #5379
but thats only a "quickfix"

with that you can just set the 'selectedTextColor' on the compiled theme (before injecting it into the context)

const muiTheme = getMuiTheme(myBaseTheme)
muiTheme.menuItem.selectedTextColor = '#BADA55'

i would prepare a PR for a 'labelSelectedStyle' if i got the OK/Feedback and time.

@dahei
Copy link

dahei commented Jan 9, 2017

@wzup @oliviertassinari

The initial question does not seem to be answered yet? How can we change the color of the selected option, as @wzup asked and described in detail?

c7f448be-d7be-11e5-8f35-1c6bc595cae0

muiTheme.menuItem.selectedTextColor = '#BADA55'

has no effect, when using a SelectField.

palette.accent1Color = 'red'

changes the color within to flyover list, when the user has opened the SelectField.

But the selected option, which is displayed, when the SelectField is closed (see screenshot) has still the old color. IMHO there is no clear solution from the answers above or I just don't get it ;)

@oliviertassinari
Copy link
Member

The question has been answered by @aaronboss, thanks!
For instance http://www.webpackbin.com/4JzBGxXUM.

@dahei
Copy link

dahei commented Jan 16, 2017

@oliviertassinari Thanks for the heads-up! labelStyle is working!

@rpk-red
Copy link

rpk-red commented Feb 22, 2018

@oliviertassinari link is not working.

@noneuf
Copy link

noneuf commented Apr 26, 2018

@oliviertassinari dead link bro

@oliviertassinari
Copy link
Member

@noneuf we are now working on v1-beta. You can always ask on StackOverflow.

@AbuKalamAzad
Copy link

AbuKalamAzad commented Mar 15, 2019

const theme = createMuiTheme({
    overrides: {
        MuiSelect: {
            select: {
                "&:focus": {
                    background: "#3A3660"
                },
                color:'white'
            }
        },
    }
});

@zannager zannager added the component: select This is the name of the generic UI component, not the React module! label Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests