React Material UI Slider component

I'm currently using the react material UI slider and I'm trying to change the default blue color of the pointer to pink. I attempted to modify the thumb and finger within the withStyles object, but unfortunately, it didn't have the desired effect.

https://material-ui.com/components/slider/

https://i.sstatic.net/1UJoE.png

My goal is to customize the color of the pointer on the slider.

Answer №1

Makestyles is a component provided by the material UI library that allows for custom styling overrides on material UI styled components. Take a look at this brief example:

import { makeStyles } from '@material-ui/core/styles';
import Slider from '@material-ui/core/Slider';

const useStyles = makeStyles({
  root: {
    width: 250,
  },
  sliderColor: {
    color: 'red'
  }
});

export default function CustomSlider() {
  const classes = useStyles();
  return (
    <div className={classes.root}>
      <Grid container spacing={2} alignItems="center"
        <Grid item xs>
          <Slider
            value={typeof value === 'number' ? value : 0}
            onChange={handleSliderChange}
            aria-labelledby="input-slider"
            className={calsses.sliderColor}
          />
        </Grid>
      </Grid>
    </div>
  );
}

Answer №2

  1. First, start by creating a custom component as shown below:
const MyCustomSlider = withStyles({
  root: {
    color: '#52af77',
    height: 8,
  },
  thumb: {
    height: 24,
    width: 24,
    backgroundColor: '#fff',
    border: '2px solid currentColor',
    marginTop: -8,
    marginLeft: -12,
    '&:focus, &:hover, &$active': {
      boxShadow: 'inherit',
    },
  },
  active: {},
  valueLabel: {
    left: 'calc(-50% + 4px)',
  },
  track: {
    height: 8,
    borderRadius: 4,
  },
  rail: {
    height: 8,
    borderRadius: 4,
  },
})(Slider);
  1. Next, you can call this custom component in your render method like so:
return {
...
 <MyCustomSlider valueLabelDisplay="auto" aria-label="custom slider" defaultValue={20} />
...
}

Source: https://material-ui.com/components/slider/ Explore customized sliders

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There is a collision of boxes occurring within the CSS

Help Needed: Overlapping Boxes in Responsive Design I am facing a problem with my CSS where the boxes on my website are overlapping when I shrink the browser window. The issue occurs as I resize the window, causing the boxes to overlap more and more. I ...

Updating the Mat Table Label Dynamically in Angular

Is there a way to dynamically change the value of a label in an Angular mat table with pagination without recreating the entire table? The goal is to update the header label without having to regenerate the whole table structure. For instance, in the tab ...

We encountered an issue loading the resource: the server has returned a 404 (Not Found) error message and a 403 Forbidden error message. However, the resource functions properly on Codepen and localhost

I have a CodePen demo that works fine. However, when I upload it to the server, it stops working properly and most external references show 404 errors. Initially, there were no problems, but now it seems to be an issue like this: !--> http://sachin.ipov ...

String variable representing the name of a React element

As I was reviewing the source code of a React UI library, I stumbled upon an interesting code pattern that I will simplify here: function Test() { let Button = "button"; // ... return <Button>Click me</Button>; } I'm curious about ...

Copying the label for data to a jQuery array can be done by selecting the desired label

Allow me to clarify I am attempting to create a jQuery array containing values copied from a form field. Below is a snippet of the HTML code. <p class="form"> <input id="Dataweekend0" class="radiob" name="form[Dataweekend]" ...

Using the JavaScript Fetch API to send information to an ASP controller

When utilizing the fetch API to send data to my asp controller, I use the following method: var data1 = {ID: '1', Name: 'John'}, data2 = {ID: '1',Action: 'Add'}; fetch('myController/MyAction',{m ...

Interact with HTML Radio Buttons to Trigger Input Opening

I need to have a message saying "We're sorry..." and a "black box" displayed only when the radio button is set to YES, otherwise keep it hidden. Can I achieve this using JavaScript only, or is there a way to do it with HTML alone? <h3 >Did you ...

Steps for triggering a function when the 'Enter' key is pressed in a TextInput in a React Native application

I'm currently working on creating a Search Bar feature. I would like the user to input text into the TextInput field, and when they press 'Enter', I want it to trigger my function. <TextInput //when the user presses Enter, call the functi ...

Enhance your data visualization with d3.js version 7 by using scaleOrdinal to effortlessly color child nodes in

Previously, I utilized the following functions in d3 v3.5 to color the child nodes the same as the parent using scaleOrdinal(). However, this functionality seems to be ineffective in d3 v7. const colorScale = d3.scaleOrdinal() .domain( [ "Parent" ...

A guide to building a dynamic form slider that showcases variable output fields with Javascript

I'm interested in creating a Slider Form that shows different output fields when sliding, using Javascript. Something like this: https://i.sstatic.net/3Isl4.png Could anyone provide suggestions on how to achieve this or share any links related to so ...

Error: foobar is not defined within this scope (anonymous function)

I'm facing an issue with a JavaScript file hosted on a domain called foobar.com. at http://foobar.com/static/js/main.js: $(document).ready(function() { function foobar(bar){ $.ajax({ url: "/site/foo/", ...

Node.js implementation to transfer MongoDB to CSV, with the unfortunate loss of certain columns

I have a script that exports a MongoDB table to CSV but I seem to be missing some columns. It appears that the column with many null values (where the first 100 rows are all null) is not being included in the exported CSV file. const mongodb = require(" ...

Struggling with integrating PHP within a JavaScript AJAX function

Here's a button I have: <button id= $id onClick="popup($id)">button</button> I am attempting to use it with an ajax function <script> function popup(id){ alert(" "); document.write(" "); } </script> My goal is to execute P ...

Storing tasks in the server backend for later access

Struggling to find the most efficient way to store todo list items in the backend. I've heard that storing arrays and objects directly in the backend may not be optimal. Currently working on a web app inspired by Google Keep. Here's some context ...

React: Utilizing a shared data store across multiple components

As I develop a React Component within a library that enables multiple instances to share state, update state, and track unmounting of all instances, I face the challenge of not being able to utilize the Context provider pattern due to the inability to wrap ...

Disable or set input text to read-only in Internet Explorer 9 and earlier versions using JavaScript or jQuery

Can anyone offer any suggestions on how to accomplish this task? I attempted using JavaScript with the code below, but it did not yield the desired results. element.readOnly="true"; element.readonly="readonly"; element.disabled="disabled"; I also tried ...

What is the best method for utilizing JSON to import Bureau of Labor Statistics information into Highcharts?

When it comes to integrating JSON files into charts, Highcharts offers some helpful examples. However, most of their samples feature rather straightforward JSON files, like this one: pretty simple JSON files. My goal is to take a JSFiddle example (http:// ...

Low frame rate in a straightforward Three.js environment on Safari for MacOS

I have created a demo that runs smoothly on Chrome and Firefox but lags terribly on Safari. Disabling antialiasing slightly improves the FPS, but not significantly. I am wondering if there are ways to optimize my code, perhaps by implementing caching techn ...

Assigning a modal value to an HTML field

I am in need of a solution for multiple HTML fields with a common modal attached to each one. The code I have currently looks like this: <!-- First Element --> <div class="box box-element ui-draggable"> <span class="config ...

Blurry black-and-white picture

As a beginner in HTML and CSS, I am still learning. I have a challenge where I have two images and when one of them is hovered over, it should increase in size and display text. Additionally, I want the image that is not in focus to appear in grayscale. Wh ...