javascript - React: How to use arrow up/down to select previous/next item in a scroll list and make the list scroll to keep the selected element on screen -


i'm using react-infinite scroll list , i'm implemented arrow up/down handler:

onkeydown = (e) => {     if(e.keycode === 40){         if (this.props.onkeydown) {             e.preventdefault()             this.props.onkeydown()         }     }     else if (e.keycode === 38) {         if (this.props.onkeyup) {             e.preventdefault()             this.props.onkeyup()         }     } } 

(the component reusable throughout application pass actual functions through props)

this works far selecting next/previous item in list. when reach edge of scroll list , keep going, list doesn't scroll keep selected item in view. selected item disappears off screen.

any appreciated!

you need method scrollintoview. present on every element. need detect when element rendered off screen getting element's offsettop , compare component's offsetheight, when number higher component's offsetheight need scroll view.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -