Merge pull request #1746 from ethereum/tabScrollIssue

fixed the scroll when zoomed in
pull/5370/head
Liana Husikyan 3 years ago committed by GitHub
commit 762addc2c3
  1. 20
      libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx
  2. 6340
      package-lock.json

@ -21,6 +21,8 @@ export const TabsUI = (props: TabsUIProps) => {
const [selectedIndex, setSelectedIndex] = useState(-1) const [selectedIndex, setSelectedIndex] = useState(-1)
const currentIndexRef = useRef(-1) const currentIndexRef = useRef(-1)
const tabsRef = useRef({}) const tabsRef = useRef({})
const tabsElement = useRef(null)
const tabs = useRef(props.tabs) const tabs = useRef(props.tabs)
tabs.current = props.tabs // we do this to pass the tabs list to the onReady callbacks tabs.current = props.tabs // we do this to pass the tabs list to the onReady callbacks
@ -53,11 +55,22 @@ export const TabsUI = (props: TabsUIProps) => {
currentIndexRef.current = index currentIndexRef.current = index
setSelectedIndex(index) setSelectedIndex(index)
} }
const transformScroll = (event) => {
if (!event.deltaY) {
return
}
event.currentTarget.scrollLeft += event.deltaY + event.deltaX
event.preventDefault()
}
useEffect(() => { useEffect(() => {
props.onReady({ props.onReady({
activateTab, activateTab,
active active
}) })
return () => { tabsElement.current.removeEventListener('wheel', transformScroll) }
}, []) }, [])
return ( return (
@ -70,8 +83,13 @@ export const TabsUI = (props: TabsUIProps) => {
<Tabs <Tabs
className="tab-scroll" className="tab-scroll"
selectedIndex={selectedIndex} selectedIndex={selectedIndex}
domRef={(domEl) => {
if (tabsElement.current) return
tabsElement.current = domEl
tabsElement.current.addEventListener('wheel', transformScroll)
}}
> >
<TabList className="d-flex flex-row justify-content-center align-items-center"> <TabList className="d-flex flex-row align-items-center">
{props.tabs.map((tab, i) => <Tab className="py-1" key={tab.name}>{renderTab(tab, i)}</Tab>)} {props.tabs.map((tab, i) => <Tab className="py-1" key={tab.name}>{renderTab(tab, i)}</Tab>)}
</TabList> </TabList>
{props.tabs.map((tab) => <TabPanel key={tab.name} ></TabPanel>)} {props.tabs.map((tab) => <TabPanel key={tab.name} ></TabPanel>)}

6340
package-lock.json generated

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