airbnb / rheostat

Rheostat is a www, mobile, and accessible slider component built with React
MIT License
1.69k stars 189 forks source link

Show tooltips on handles while dragging #134

Open divyanshu013 opened 6 years ago

divyanshu013 commented 6 years ago

Hi, great work on rheostat. I'm looking for a way to render a tooltip which would display the current value of the slider while it's being dragged. What would be the best way to achieve this?

Reference - https://github.com/react-component/slider

Thanks!

itsdouges commented 6 years ago

Atm I've gotten around this by using the following code:

import Rheostat from 'rheostat';

<Rheostat
    handle={({ className: _, ...handleProps }: HandleProps) => (
    <Handle {...handleProps}>
        <HandleTooltip>
        <DateLabel>
            {moment(start)
            .add(handleProps['aria-valuenow'], type)
            .format('Do MMM')}
        </DateLabel>
        </HandleTooltip>
    </Handle>
    )}
...
/>

Note that I'm dipping into the aria tag aria-valuenow to get the current value, so I can then show it on the handle. It's definitely not how it was intended to be used, but it works. Maybe we can get better custom handle support soon, I'd be willing to contribute.