iozbeyli / react-semantic-ui-range

A Semantic UI Slider for React
MIT License
39 stars 10 forks source link

Multiple slider doesn't render start values #13

Open brambow opened 5 years ago

brambow commented 5 years ago

Using v0.7.0

import React, { useState } from 'react';
import { Segment } from 'semantic-ui-react';
import { Slider } from 'react-semantic-ui-range';

const FilterSlider = () => {
  const [values, setValues] = useState([0, 5000]);
  const settings = {
    start: [0, 5000],
    min: 0,
    max: 5000,
    step: 1,
    onChange: array => {
      setValues(array);
    }
  };
  return (
    <Segment>
      <Slider multiple value={values} color="teal" settings={settings} />
    </Segment>
  );
};

export default FilterSlider;

Result on first render: image

What I expect to see image

brambow commented 5 years ago

Interestingly, when I attempted my actual use case, which was dynamically adding the slider based on a button click, it renders as expected:

image

renato commented 4 years ago

I was having the same issue, but testing a little further the it happened with non-multiple ranges too.

Apparently it happens when the Slider isn't visible on initialization. On my scenario it was inside a <Accordion/>, so if the inner panel isn't visible when the Slider is first rendered, the start values don't show up because this.inner.offsetWidth equals 0.

https://github.com/iozbeyli/react-semantic-ui-range/blob/6f537a0b3e36fd24531310665ad7b72b4803e524/lib/elements/slider.js#L92-L96

I could try a PR but I don't know if @iozbeyli is still accepting them.

TimMcCauley commented 2 years ago

Greetings @renato - I am facing the same issue. Do you have a workaround at hand?

renato commented 2 years ago

Hey @TimMcCauley, I ended up using another slider component (rc-slider), so I don't have a workaround at hand, unfortunately.

TimMcCauley commented 2 years ago

Thank you @renato, I will check it out! Appreciated.