Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
muiSlider restrict for certaing range

i'm usign below Mui Slider component for a UI where i have to restrict it's value for certaing range. For example slider's ball will not dragable after 50. user can select values upto 50 but it will show it full range. i didn't found any direct solution so i figured out a bypass with Discrete Slider Values. here's the code sandbox link ,Where i have make a array of full available values. Is there any neat and clean solution ?

<Slider
  size="small"
  defaultValue={30}
  aria-label="Small"
  valueLabelDisplay="auto"
/>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you have to determine max value for yor slider like below

<Slider
   ...
   max={50}
   min={0}
/>

And i see your code and i think you can determine marks array for just labels not all values

about 4 years ago · Juan Pablo Isaza Report

0

Hello Fazlay Rabbi it's so simple you need just think out of the box, just need to write simply if condition I write your solution in blow :

import React, { useState } from "react";
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';

export default function DiscreteSliderLabel() {
  const [sliderValue, setSliderValue] = useState(0);
  
  const handleChange2 = (event, newValue) => {
   
    if (newValue > 50){
      setSliderValue(50);
    }else{
      setSliderValue(newValue);
    }
    
  };

  return (
    <Box sx={{ width: 300 }}>
      <Slider
        value={sliderValue}
        aria-label="Always visible"
        onChange={handleChange2}
        valueLabelDisplay="on"
      />
    </Box>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!