Skip to content

Commit

Permalink
fix: tabs 小程序滚动操作问题 (jdf2e#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyang1020 authored Mar 7, 2024
1 parent 7ae611f commit 8256b54
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/packages/tabs/tabs.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {

animate()
}
const scrollIntoView = () => {
const scrollIntoView = (index: number) => {
raf(() => {
Promise.all([
getRect(`#nut-tabs-titles-${name || uuid} .nut-tabs-list`),
Expand All @@ -192,14 +192,14 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
navRectRef.current = navRect
titleRectRef.current = titleRects
// @ts-ignore
const titleRect: RectItem = titleRectRef.current[value]
const titleRect: RectItem = titleRectRef.current[index]
if (!titleRect) return

let to = 0
if (props.direction === 'vertical') {
const DEFAULT_PADDING = 11
const top = titleRects
.slice(0, value)
.slice(0, index)
.reduce(
(prev: number, curr: RectItem) => prev + curr.height,
DEFAULT_PADDING
Expand All @@ -208,7 +208,7 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
} else {
const DEFAULT_PADDING = 20
const left = titleRects
.slice(0, value)
.slice(0, index)
.reduce(
(prev: number, curr: RectItem) => prev + curr.width,
DEFAULT_PADDING
Expand All @@ -233,7 +233,7 @@ export const Tabs: FunctionComponent<Partial<TabsProps>> & {
: `translate3d( 0,-${index * 100}%, 0)`,
transitionDuration: `${duration}ms`,
})
scrollIntoView()
scrollIntoView(index)
}, [value])

const tabChange = (item: TabsTitle, index: number) => {
Expand Down

0 comments on commit 8256b54

Please sign in to comment.