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

Scrollable - showcase ability to set the scroll from outside, programmatically #55

Open
yairEO opened this issue Feb 7, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@yairEO
Copy link
Contributor

yairEO commented Feb 7, 2022

Currently the Scrollable demos only showcase the ability to control the scroll using the dedicated <Scrollable.VerticalScrollbar> component, which has a unique access to the context.

This ability (control the scroll position) is also important to have from any other component on the page.

Below is a non-tested idea for such a demo:

const getVerticalMiddleDistanceInPx = elem => ...

const OutsideScrollControl = ({children}) => {
	const scrollRef = useRef();

	const scrollTo = (top, left) => {
	  scrollRef.current.scroll({top,  left, behavior: 'smooth'})
	}

    return <>
	  <button onClick={scrollTo(0)}>scroll to top</button>
	  <button onClick={scrollTo( getVerticalMiddleDistanceInPx(scrollRef.current) )}>scroll to middle</button>
	  <button onClick={scrollTo(100, 100)}>scroll 100px vertical  & horizontal</button>

	  <Scrollable element={<div ref={scrollRef}/>}>
	      imagine long content...
	  </Scrollable>
	</>
}
@yairEO yairEO added the enhancement New feature or request label Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant