react-component / react-component/slider

Updating Range Slider Counts via props doesn't update Slider

Open
#639 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.1k
Forks
768
Avg merge
11d 22h
Merged PRs (30d)
5

Description

I have a slider who's count prop is dictated by a prop passed into the slider's parent component. When I update the number of counts, the range slider doesn't update, despite it's props showing correct values.

I'd expect to see as many handles as there are the value passed to 'count'

import React, { useState, useEffect } from 'react';
import { Range } from 'rc-slider';

const ClassBreakSlider = ({ minMax, originalMinMax, colors, breakPoints, onSliderChange }) => {
  const { originalMin, originalMax } = originalMinMax;
  const { min, max } = minMax;

  const [values, setValues] = useState([min, ...breakPoints, max]);

  const handleStyles = colors.map((color) => {
    return {
      backgroundColor: color,
      border: '1px #cccccc solid',
    };
  });
  const trackStyles = colors.map((color) => {
    return {
      backgroundColor: color,
    };
  });

  const handleChange = (sliderValues) => {
    onSliderChange(sliderValues);
    setValues(sliderValues);
  };

  useEffect(() => {
    setValues([min, ...breakPoints, max]);
  }, [breakPoints]);

  return (
    <Range
      count={breakPoints.length}
      defaultValue={[min, ...breakPoints, max]}
      values={values}
      min={originalMin}
      max={originalMax}
      allowCross={false}
      step={1}
      pushable={true}
      trackStyle={trackStyles}
      handleStyle={handleStyles}
      onChange={handleChange}
    />
  );
};

export default ClassBreakSlider;

Screen Shot 2020-03-19 at 11 36 24 AM

Screen Shot 2020-03-19 at 11 38 09 AM

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Range component usage in the reported ClassBreakSlider example and trace how its count and values props are handled when breakPoints changes. Reproduce the update with changing breakPoints, then add or adjust coverage so the rendered handles match the new count and confirm the existing range behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.