Skip to content

fix(noticebar): first item is not visible when scrolling vertically #3249

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

Open
wants to merge 1 commit into
base: feat_v3.x
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/packages/noticebar/__test__/noticebar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,43 @@ test('vertical event test', async () => {
fireEvent.click(box)
await waitFor(() => expect(handleClick).toBeCalled())
})

test('vertical container height calculation with children', async () => {
const horseLamp1 = [
'NoticeBar 公告栏',
'Cascader 级联选择',
'DatePicker 日期选择器',
'CheckBox 复选按钮',
]
const height = 50
const { container } = render(
<NoticeBar direction="vertical" height={height} speed={10} duration={1000}>
{horseLamp1.map((item, index) => {
return (
<div
className="custom-item"
style={{ height: `${height}px`, lineHeight: `${height}px` }}
key={index}
>
{item}
</div>
)
})}
</NoticeBar>
)

await waitFor(
() => {
const wrapElement = container.querySelector('.nut-noticebar-box-wrap')
if (wrapElement) {
// 验证容器高度应该是 (childCount + 1) * height
// childCount = 4, height = 50, 所以期望高度是 (4 + 1) * 50 = 250px
const expectedHeight = `${(horseLamp1.length + 1) * height}px`
console.log(wrapElement, 'wrapElement')
expect(wrapElement).toHaveStyle(`height: ${expectedHeight}`)
}
},
// 由于init中并不会立刻设置样式,所以需要等待一段时间
{ timeout: 3000 }
)
})
2 changes: 1 addition & 1 deletion src/packages/noticebar/noticebar.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export const NoticeBar: FunctionComponent<
target.style.transitionDuration = `${
swiperRef.current.moving ? 0 : duration
}ms`
target.style.height = `${Number(height) * childCount}px`
target.style.height = `${Number(height) * (childCount + 1)}px`
target.style.transform = `translate3D(0,${_offset}px,0)`
}
// 无缝滚动第一个元素位移控制
Expand Down
2 changes: 1 addition & 1 deletion src/packages/noticebar/noticebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export const NoticeBar: FunctionComponent<
target.style.transitionDuration = `${
swiperRef.current.moving ? 0 : duration
}ms`
target.style.height = `${Number(height) * childCount}px`
target.style.height = `${Number(height) * (childCount + 1)}px`
target.style.transform = `translate3D(0,${_offset}px,0)`
}
// 无缝滚动第一个元素位移控制
Expand Down
Loading