-
Notifications
You must be signed in to change notification settings - Fork 266
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
feat(Backtop): refactor backtop using hoverbutton and v15 adaption #2866
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
935422d
refactor: use hoverbutton
xiaoyatong b4461f9
fix: 鸿蒙下露出
xiaoyatong 9fbbff1
fix: merge
xiaoyatong c79fd17
test: fixed
xiaoyatong e6e0a20
test: add tests
xiaoyatong 875e323
feat: 支持 icon
xiaoyatong 83883a4
fix: lint ts
xiaoyatong 41de6eb
test: update case
oasis-cloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,7 @@ | |
"tarodoc": true, | ||
"show": true, | ||
"taro": true, | ||
"v15": true, | ||
"author": "vickyYe" | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import * as React from 'react' | ||
import '@testing-library/jest-dom' | ||
import { Top } from '@nutui/icons-react' | ||
import { render, fireEvent } from '@testing-library/react' | ||
import { act, fireEvent, render, waitFor } from '@testing-library/react' | ||
import BackTop from '@/packages/backtop' | ||
|
||
test('backtop props test', () => { | ||
|
@@ -37,31 +37,46 @@ test('backtop custom test', () => { | |
}} | ||
onClick={handleClick} | ||
> | ||
<div | ||
className="backtop-demo" | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Top width="12px" height="12px" className="nut-backtop-main" /> | ||
<div style={{ fontSize: '12px' }}>顶部</div> | ||
</div> | ||
<Top /> | ||
<div style={{ fontSize: '12px' }}>顶部</div> | ||
</BackTop> | ||
) | ||
expect(container.querySelector('.nut-backtop')).toHaveAttribute( | ||
'style', | ||
'z-index: 900; bottom: 110px; right: 10px;' | ||
) | ||
expect(container.querySelector('.backtop-demo')).toHaveAttribute( | ||
'style', | ||
'display: flex; flex-direction: column; align-items: center;' | ||
) | ||
expect(container.querySelector('.nut-icon-Top')).toHaveClass( | ||
'nut-backtop-main' | ||
) | ||
fireEvent.click(container) | ||
expect(handleClick).toBeCalled | ||
Alex-huxiyang marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 少了() |
||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('scroll', async () => { | ||
const { container } = render( | ||
<div id="target" style={{ height: '100px' }} className="backtop-wrapper"> | ||
{new Array(24).fill(0).map((_, index) => { | ||
return ( | ||
<div key={index} style={{ height: 30 }}> | ||
我是测试数据{index} | ||
</div> | ||
) | ||
})} | ||
<BackTop target="target" className="backtop-button" /> | ||
</div> | ||
) | ||
const track = container.querySelector('.backtop-wrapper') | ||
const element18 = container.querySelectorAll( | ||
'.nut-hoverbutton-item-container' | ||
)[0] | ||
const element19 = container.querySelectorAll('.nut-hoverbutton-container')[0] | ||
if (track) { | ||
track.scrollTo = vi.fn() | ||
track.scrollTop = 200 | ||
act(() => { | ||
track.dispatchEvent(new Event('scroll')) | ||
}) | ||
await waitFor(() => { | ||
expect(element19).toHaveClass('nut-backtop-show') | ||
}) | ||
fireEvent.click(element18 as Element) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
.nut-backtop { | ||
display: none; | ||
position: fixed; | ||
|
||
&-rn { | ||
position: absolute; | ||
} | ||
|
||
&-show { | ||
width: 40px; | ||
height: 40px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background: $color-background-overlay; | ||
color: $color-title; | ||
border: 1px solid $backtop-border-color; | ||
border-radius: 21px; | ||
z-index: 100; | ||
|
||
&:active, | ||
&-active { | ||
background: $color-background; | ||
} | ||
} | ||
|
||
&-main { | ||
width: $hoverbutton-item-size; | ||
height: $hoverbutton-item-size; | ||
transition: all 0.2s ease-in-out; | ||
color: $color-title; | ||
.nut-hoverbutton-item-container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
需要更新文档和 CHANGELOG
根据验证结果,虽然在
config.json
中添加了 v15 版本的配置,但是相关的文档和 CHANGELOG 尚未更新。为确保代码变更的完整性,请:🔗 Analysis chain
版本标记更新
添加了
"v15": true
配置,表明组件已适配 v15 版本。建议:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 45
Script:
Length of output: 584