added vertical scroll to tabs

pull/5370/head
lianahus 3 years ago committed by yann300
parent 76b418e6f4
commit b022e1dc6e
  1. 18
      libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx
  2. 6340
      package-lock.json

@ -53,11 +53,29 @@ export const TabsUI = (props: TabsUIProps) => {
currentIndexRef.current = index currentIndexRef.current = index
setSelectedIndex(index) setSelectedIndex(index)
} }
const scrollToNextTab = (event) => {
const next = event.deltaY > 0
let scrollTo = currentIndexRef.current
if (next) {
if (currentIndexRef.current < props.tabs.length - 1) {
scrollTo = currentIndexRef.current + 1
tabsRef.current[scrollTo].scrollIntoView({ behavior: 'smooth', block: 'center' })
}
} else {
if (currentIndexRef.current > 0) {
scrollTo = currentIndexRef.current - 1
tabsRef.current[scrollTo].scrollIntoView({ behavior: 'smooth', block: 'center' })
}
}
}
useEffect(() => { useEffect(() => {
props.onReady({ props.onReady({
activateTab, activateTab,
active active
}) })
window.addEventListener('wheel', scrollToNextTab)
return () => { window.removeEventListener('wheel', scrollToNextTab) }
}, []) }, [])
return ( return (

6340
package-lock.json generated

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save