slider icon indicating copy to clipboard operation
slider copied to clipboard

slider tooltip not tracking with handle

Open orro3790 opened this issue 5 years ago • 3 comments

I see this is a recurring bug, but has anyone found a work-around? When sliding the handle, the value updates properly but the tooltip remains static until mouse release, then clicking on the handle again brings the tooltip to mouse position.

orro3790 avatar May 06 '20 03:05 orro3790

+1

stefanue avatar May 07 '20 10:05 stefanue

I solved this issue by creating my own tooltip:

const Handle = Slider.Handle;

const handle = (props) => {
      const { value, dragging, index, ...restProps } = props;
      return (
         <Handle value={value} {...restProps}>
            <div className="inner">
               <div className={`wdc-tooltip${dragging ? ' active' : ''}`}>
                  <span className="wdc-tooltip-inner">{value}</span>
               </div>
            </div>
         </Handle>
      );
};

and rendering the component like this:

<Slider
   step="10"
   handle={handle}
/>

You will need to add some css to style it, and no need for using other components such as <Tooltip>

here's my scss:

.wdc-tooltip {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    z-index: 9999;
    font-size: 10px;
    line-height: 1.5;
    opacity: 0.9;
    user-select: none;
    visibility: hidden;
    opacity: 0;
    transition: all ease-in-out 150ms;
    &.active {
        visibility: visible;
        opacity: 1;
        top: -10px;
    }
    span {
        display: block;
        text-align: center;
        color: #fff;
        text-decoration: none;
        background-color: #373737;
        border-radius: 5px;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.17);
        position: relative;
        font-weight: bold;
        user-select: none;
        padding: 5px 10px;
        &:after {
            content: '';
            position: absolute;
            width: 0;
            height: 0;
            border-color: transparent;
            border-style: solid;
            border-width: 5px 5px 0;
            border-top-color: #373737;
            left: 50%;
            bottom: 0;
            transform: translate(-50%, 100%);
        }
    }
}

stefanue avatar May 07 '20 10:05 stefanue

I solved this issue by creating my own tooltip:

const Handle = Slider.Handle;

const handle = (props) => {
      const { value, dragging, index, ...restProps } = props;
      return (
         <Handle value={value} {...restProps}>
            <div className="inner">
               <div className={`wdc-tooltip${dragging ? ' active' : ''}`}>
                  <span className="wdc-tooltip-inner">{value}</span>
               </div>
            </div>
         </Handle>
      );
};

and rendering the component like this:

<Slider
   step="10"
   handle={handle}
/>

You will need to add some css to style it, and no need for using other components such as <Tooltip>

here's my scss:

.wdc-tooltip {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    z-index: 9999;
    font-size: 10px;
    line-height: 1.5;
    opacity: 0.9;
    user-select: none;
    visibility: hidden;
    opacity: 0;
    transition: all ease-in-out 150ms;
    &.active {
        visibility: visible;
        opacity: 1;
        top: -10px;
    }
    span {
        display: block;
        text-align: center;
        color: #fff;
        text-decoration: none;
        background-color: #373737;
        border-radius: 5px;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.17);
        position: relative;
        font-weight: bold;
        user-select: none;
        padding: 5px 10px;
        &:after {
            content: '';
            position: absolute;
            width: 0;
            height: 0;
            border-color: transparent;
            border-style: solid;
            border-width: 5px 5px 0;
            border-top-color: #373737;
            left: 50%;
            bottom: 0;
            transform: translate(-50%, 100%);
        }
    }
}

Property 'Handle' does not exist on type 'ForwardRefExoticComponent<SliderProps<number | number[]> & RefAttributes<SliderRef>>'. Maybe it worked with previous versions but with "rc-slider": "^10.6.2" it doesn't work. Does anyone know how to solve this problem with the latest version?

Argam11 avatar Jun 28 '24 14:06 Argam11