Slider: Custom handle doesn't work

Created on 18 Jul 2018  路  2Comments  路  Source: react-component/slider

Custom handle doesn't seem to work.

Here's the code, also available on codesandbox:

import React from "react";
import ReactDOM from "react-dom";

import Slider from "rc-slider/lib/Slider";
import "rc-slider/assets/index.css";

const Handle = () => <span style={{fontSize: '3rem'}}>*</span>;

function App() {
  return (
    <div style={{ paddingTop: "30vh" }}>
      <Slider handle={Handle} />
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Here's the experience so far:
handle

Most helpful comment

The handle prop is quite low-level. It expects you to implement the Handle functionality yourself on your custom Handle.

But, you can use the existing Handle component and pass your custom children to it:

import Slider, { Handle } from 'rc-slider'

<Slider
    handle={ (handleProps) => {
        return (
            <Handle { ...handleProps }>
                <MyAwesomeComponent />
            </Handle>
        )
    }}
 />

All 2 comments

The handle prop is quite low-level. It expects you to implement the Handle functionality yourself on your custom Handle.

But, you can use the existing Handle component and pass your custom children to it:

import Slider, { Handle } from 'rc-slider'

<Slider
    handle={ (handleProps) => {
        return (
            <Handle { ...handleProps }>
                <MyAwesomeComponent />
            </Handle>
        )
    }}
 />

The code suggested by @draperunner works well. This issue can be closed now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeznag picture jeznag  路  6Comments

OlivierCo picture OlivierCo  路  5Comments

nitroamos picture nitroamos  路  4Comments

sonovice picture sonovice  路  7Comments

koenvo picture koenvo  路  5Comments