• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

80
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"
/>
almost 3 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

almost 3 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>
  );
}
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error