slider icon indicating copy to clipboard operation
slider copied to clipboard

How to use createSliderWithTooltip

Open jcubic opened this issue 3 years ago • 6 comments

The code from the documentation doesn't work. It gives a warning from TypeScript that you can replace require with import but it throws a runtime error:

react-dom.development.js:11865 Uncaught TypeError: createSliderWithTooltip is not a function

jcubic avatar Dec 08 '22 13:12 jcubic

@jcubic It looks like this library was refactored recently and the most recent documentation now exists in the docs/ directory. Here is the implementation included for the TooltipSlider: https://github.com/react-component/slider/blob/master/docs/examples/components/TooltipSlider.tsx

vf-telwing avatar Jan 06 '23 18:01 vf-telwing

I don't think I will waste more time on this.

jcubic avatar Jan 06 '23 22:01 jcubic

Can you please let me know how this can be resolved?

This is what I have: const { createSliderWithTooltip } = Slider; const Range = createSliderWithTooltip(Slider.Range);

But this gives the following error: Property 'createSliderWithTooltip' does not exist on type 'ForwardRefExoticComponent<SliderProps<number | number[]> & RefAttributes<SliderRef>>'

anik95 avatar Jan 10 '23 13:01 anik95

@anik95 Since createSliderWithTooltip no longer exists, the best reference point I was able to find is the TooltipSlider example: https://github.com/react-component/slider/blob/master/docs/examples/components/TooltipSlider.tsx

I think that component is the intended replacement for the code you are currently using.

vf-telwing avatar Jan 10 '23 14:01 vf-telwing

I literally spent half of a day on this...

For anyone who encounter the same problem, my suggestions are:

  • Use old version of rc-slider, i.e., v9.x.x;
  • Use antd library instead, though it is huge;
  • Use the template mentioned above;
  • Giving up on the tooltip function, rc-tooltip is even more unreliable;

But if you insist on using this version of rc-slider by yourself, This is a cleaner example than the template above:

import React from "react";
import Slider from "rc-slider"; // 10.0.0
import Tooltip from "rc-tooltip"; // 5.1.1
import "rc-tooltip/assets/bootstrap_white.css";

export default () => (
  <div>
    <Slider
      handleRender={(node, handleProps) => {
        return (
          <Tooltip
            overlayInnerStyle={{ minHeight: "auto" }}
            overlay={"score: " + handleProps.value}
            placement="bottom"
          >
            {node}
          </Tooltip>
        );
      }}
      range
      min={0}
      max={10}
      defaultValue={[1, 2, 3]}
    ></Slider>
  </div>
);

Oh, never to mention that it generates error of ReactDOM.render is no longer supported in React 18 all the time.

Working on this is just WASTE OF TIME.

wzy1935 avatar Feb 12 '23 11:02 wzy1935