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

fix: 初始化滚动到指定项 (#195) #196

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vantui-demo/src/pages/tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class Index extends Component {
tabs2: [1, 2],
tabs3: [1, 2, 3, 5, 6],
tabs4: [1, 2, 3, 4],
tabs6: [1, 2, 3, 4, 5, 6],
tabs6: [1, 2, 3, 4, 5, 6, 7, 8],
tabsWithName: [
{ name: 'a', index: 1 },
{ name: 'b', index: 2 },
Expand Down Expand Up @@ -80,7 +80,7 @@ export default class Index extends Component {
</Tabs>
</DemoBlock>
<DemoBlock title="横向滚动">
<Tabs>
<Tabs active={6}>
{tabs6.map((item, index) => {
return (
<Tab key={index} title={'标签 ' + item}>
Expand Down
21 changes: 14 additions & 7 deletions packages/vantui/src/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,23 @@ export function Tabs(props: TabsProps) {
),
}
})
setTimeout(() => {
resize()
scrollIntoView()
if (active !== getCurrentName()) {
setCurrentIndexByName(active)
}
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(
function () {
setTimeout(() => {
resize()
scrollIntoView()
if (active !== getCurrentName() && !ref.current?.swiping) {
setCurrentIndexByName(active)
}
}, 16)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[getCurrentName()],
)

useEffect(
function () {
resize()
Expand Down