javascript - How to output current values from the rc-slider react component? - Stack Overflow

I installed the rc-slider React Component on my React app, but I need to output the current values from

I installed the rc-slider React Component on my React app, but I need to output the current values from the slider, how do I do that? This is the current code:

import React from 'react';
import 'rc-slider/assets/index.css';
import 'rc-tooltip/assets/bootstrap.css';
import Slider from 'rc-slider';

const createSliderWithTooltip = Slider.createSliderWithTooltip;
const Range = createSliderWithTooltip(Slider.Range);

export class RangeSlider extends React.Component {
  render() {
    return (
      <div>
        <Range min={0} max={10000} defaultValue={[800, 3000]} tipFormatter={value => `${value}€`} />
      </div>      
    )
  }
}

Also, how do I change the font-family from the tooltip where values are displayed when grabbing slider's handles?

I installed the rc-slider React Component on my React app, but I need to output the current values from the slider, how do I do that? This is the current code:

import React from 'react';
import 'rc-slider/assets/index.css';
import 'rc-tooltip/assets/bootstrap.css';
import Slider from 'rc-slider';

const createSliderWithTooltip = Slider.createSliderWithTooltip;
const Range = createSliderWithTooltip(Slider.Range);

export class RangeSlider extends React.Component {
  render() {
    return (
      <div>
        <Range min={0} max={10000} defaultValue={[800, 3000]} tipFormatter={value => `${value}€`} />
      </div>      
    )
  }
}

Also, how do I change the font-family from the tooltip where values are displayed when grabbing slider's handles?

Share Improve this question edited Jul 12, 2018 at 16:53 Tholle 113k22 gold badges208 silver badges197 bronze badges asked Jul 12, 2018 at 16:36 soalribsoalrib 5993 gold badges9 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You could store the slider values in state and use the onChange prop to update the slider values when they change.

The function given to tipFormatter can also return JSX as well as a string, so you can add a custom className and change font-family for that class.

Example

export class RangeSlider extends React.Component {
  state = { sliderValues: [800, 3000] };

  handleChange = sliderValues => {
    this.setState({ sliderValues });
  };

  render() {
    const { sliderValues } = this.state;
    return (
      <div>
        {sliderValues[0]} - {sliderValues[1]}
        <Range
          min={0}
          max={10000}
          onChange={this.handleChange}
          defaultValue={sliderValues}
          tipFormatter={value => <span className="tooltip">{value}€</span>}
        />
      </div>
    );
  }
}

For some reason, that last part of your code was not working for me as I was trying to get the range tooltip to animate correctly and display the correct data. I had to install an older version of rc-slider (8.7.1) in order to fix the tooltip animation that is currently broken at the time of this post. The code fix that got it all working correctly with the older version was: ... tipFormatter={value => ${value}} tipProps={{visible: true}} ...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744155750a4560851.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信