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

[Slider] should support setting colors not in the theme #6127

Closed
acroyear opened this issue Feb 12, 2017 · 5 comments
Closed

[Slider] should support setting colors not in the theme #6127

acroyear opened this issue Feb 12, 2017 · 5 comments
Labels
component: slider This is the name of the generic UI component, not the React module! v0.x

Comments

@acroyear
Copy link
Contributor

acroyear commented Feb 12, 2017

Problem description

The style and sliderStyle properties in Slider don't actually affect the slider colors. They create a background-color box but the component colors remain unchanged from the ancestor theme. This is not a useful thing.

There are use-cases for needing to easily change the color, just like one can change an icon or fab color, without going through all the details of creating a new mui-theme just to wrap the slider.

Workarounds involving CSS aren't dynamic because the CSS is only loaded once. Workarounds involving finding the relevant divs and setting their colors don't work on the "knob" of the slider because the div is re-rendered, so the style (somehow) needs to be re-applied on every value change.

Thus, the only consistent workaround is to create a new dynamic theme just for the color change here, which seems to be a lot of code for such a little need.

Versions

  • Material-UI: 0.16.7
@acroyear
Copy link
Contributor Author

acroyear commented Feb 12, 2017

Well, not a lot of code for the user, but a bit of execution code creating the alt theme. (I originally posted that it didn't work, but I'd not structured the alt theme correctly, so removed that as being my fault).

put this in your own theme file

export var replaceSliderTheme = function(posColor, negColor) {
  console.log("replace", posColor, negColor);
  var rv = {
    spacing: spacing,
    fontFamily: 'Roboto, sans-serif',
    palette: {
      primary1Color: posColor,
      accent1Color: posColor,
      disabledColor: negColor || fade(fullWhite, 0.3),
      // (and rest of the colors being your original theme
    }
  }
  return rv;
}

then call it by

const sliderTheme = replaceSliderTheme(myAltColor);

and

<MuiThemeProvider muiTheme={getMuiTheme(sliderTheme)}> <Slider /> </MuiThemeProvider>

so having a more direct mechanism would be nice, but this workaround suits my purposes without having to style-hack the divs.

@oliviertassinari oliviertassinari added the component: slider This is the name of the generic UI component, not the React module! label Feb 13, 2017
@dehjli85
Copy link

being able to just pass a prop to the Slider component to change the color would be ideal.

@oliviertassinari
Copy link
Member

We plan on migrating the component to the v1-beta branch. I'm closing the issue for #4793.

@acroyear
Copy link
Contributor Author

acroyear commented Dec 9, 2017

Heh - I hadn't realized the slider wasn't in "@next" yet. Is there a timetable on that because I'm gonna need it somewhat soon (working on a rewrite of a music player). :)

@acroyear
Copy link
Contributor Author

acroyear commented Dec 9, 2017

anyways, theme creation doesn't seem as heavyweight as i thought it would be, so if changing the theme instead of just passing in a property is the way to do it still, I'll be ok with that...but having properties certainly makes it easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: slider This is the name of the generic UI component, not the React module! v0.x
Projects
None yet
Development

No branches or pull requests

3 participants