slider icon indicating copy to clipboard operation
slider copied to clipboard

Indication for focus

Open Vishal1419 opened this issue 3 years ago • 7 comments

I have checked the documentation and other issues, but unfortunately I cannot find any way to add box-shadow or change color of the handle when there is a focus on the handle. I am using slider in single handle mode.

Is there any way to achieve this?

Vishal1419 avatar Aug 19 '20 12:08 Vishal1419

I try to override the global style, it works:

.rc-slider-handle-dragging {
    box-shadow: 0 0 0 5px red !important;
}

B-l-u-e-b-e-r-r-y avatar Jul 14 '21 10:07 B-l-u-e-b-e-r-r-y

Yeah this is not amazing. I decided to add a class directly to the slider instead of the handle, and target the focus-within pseudo-class so that my slider has a ring around it whenever there is a focus on the handle. This was particularly preferable in my case, since I am using tailwind and wanted to avoid creating a custom class.

MegaKeegMan avatar Feb 11 '22 04:02 MegaKeegMan

If you don't want to restrict the color you can clone the handle within handleRender allowing you to change styling dynamically (classNames might be possible too but typescript didn't like it since they aren't defined on the HandleProps interface and thus you can't extract them to preserve them):

const draggingShadowStyle = "0 0 4px 2px #f80000";

const handleRender: SliderProps["handleRender"] = (node, nodeProps) => {
    return (
        <div 
            {...node.props}
            style={
                nodeProps.dragging 
                    ? { ...node.props.style, boxShadow: draggingShadowStyle}
                    : node.props.style
            }
    );
}

HughParsons avatar May 31 '22 21:05 HughParsons

Where did you find the documentation that shows you how to use handleRender?

AlfredMadere avatar Mar 10 '23 18:03 AlfredMadere

Where did you find the documentation that shows you how to use handleRender?

Not too sure to be honest. I think I just went off the types in ~~slider.d.ts~~. Edit: sorry I meant Slider.tsx

HughParsons avatar Mar 10 '23 20:03 HughParsons

Gotcha, do you know if there is a similar way to modify the individual sections of the track?

For example, if I have 5 handles and I want to add distinct text to the track between two of the handles, is there a way to do this?

AlfredMadere avatar Mar 10 '23 21:03 AlfredMadere

If you check out Slider.tsx there isn't a corresponding render prop for the track.

However, for that specific example you could have some shared state/object store refs or position information for each of the handles (updating within handleRender) and then use that information to calculate the position for the text.

HughParsons avatar Mar 11 '23 04:03 HughParsons