Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please export SliderRef #891

Closed
alissaVrk opened this issue May 6, 2023 · 3 comments · Fixed by #905
Closed

please export SliderRef #891

alissaVrk opened this issue May 6, 2023 · 3 comments · Fixed by #905

Comments

@alissaVrk
Copy link

so we can forwardRef properly

@nag-murali
Copy link

nag-murali commented May 23, 2023

May be you can use this to create custom handle. ( "rc-slider": "^10.1.1" )

`import { forwardRef } from "react"

const RangeHandle = forwardRef(({ index, ...restProps }, ref) => {

const defaultHandleStyle = {
  position: 'absolute',
  top: '15%',
  zIndex: 1,
  backgroundColor: '#fff',
  border: '1px solid #ddd',
  borderRadius: '50%',
  width: '20px',
  height: '20px',
  cursor: 'pointer'
}
const handleStyle = {...defaultHandleStyle, ...restProps.props.style}
const handleTouchStart = e => {
  if (index !== 2 ) {
    return e.preventDefault()
  } else {
    return restProps.props.onTouchStart(e)
  }
}
const handleMouseDown = e => {
  if (index !== 2 ) {
    return e.preventDefault()
  } else {
    restProps.props.onMouseDown(e)
  }
}

return (
  <div
    ref={ref}
    {...restProps.props}
    onTouchStart={handleTouchStart}
    onMouseDown={handleMouseDown}
    style={handleStyle}

  />
)

})

const RangeSlider = () => {
const handleRender = (handleCreateprops, handleInstanceProps) => {
return <RangeHandle index={handleInstanceProps.index} {...handleCreateprops} />
}

return (
<Slider
min={0}
max={100}
range
count={2}
defaultValue={[25, 75, 10]}
handleRender={handleRender}
pushable={false}
keyboard={false}
allowCross={false}
/>
)
}

export default RangeSlider
`

@alissaVrk
Copy link
Author

@nag-murali I was referring the type
right now I do
import RcSlider, { SliderProps, SliderRef } from 'rc-slider/lib/Slider';
importing internals feels wrong though.

the Slider component does have a ref property

@alissaVrk
Copy link
Author

@yoyo837 thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants