slider tooltip not tracking with handle

Created on 6 May 2020  路  2Comments  路  Source: react-component/slider

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.

Most helpful comment

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%);
        }
    }
}

All 2 comments

+1

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%);
        }
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gpinhey picture gpinhey  路  6Comments

Bernabe-Felix picture Bernabe-Felix  路  3Comments

eldyvoon picture eldyvoon  路  6Comments

ka7eh picture ka7eh  路  3Comments

johnb8005 picture johnb8005  路  6Comments