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

Support override anchor default onClick scroll behavior by respect preventDefault #29188

Conversation

ulion
Copy link

@ulion ulion commented Feb 2, 2021

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

Anchor onClick handler does not respect preventDefault, currently it always call scrollTo. But, if the target anchor is hidden (e.g. collapsed), if I want to first expand it, then scroll to, currently there is no way to avoid the scrollTo jumping since AnchorLink always calls scrollTo after onClick, does not check whether the event isDefaultPrevented().
With this PR, now user can do their own logic in the onClick, without the default scrollTo behavior.

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is not needed
  • Demo is not needed
  • TypeScript definition is updated
  • Changelog is provided or not needed

@ant-design-bot
Copy link
Contributor

ant-design-bot commented Feb 2, 2021

@codecov
Copy link

codecov bot commented Feb 2, 2021

Codecov Report

Merging #29188 (32b12da) into master (8158f45) will decrease coverage by 0.01%.
The diff coverage is 99.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##            master   #29188      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          393      394       +1     
  Lines         7466     7486      +20     
  Branches      2152     2142      -10     
===========================================
+ Hits          7466     7485      +19     
- Misses           0        1       +1     
Impacted Files Coverage Δ
components/anchor/Anchor.tsx 100.00% <ø> (ø)
components/locale/en_GB.tsx 100.00% <ø> (ø)
components/slider/index.tsx 100.00% <ø> (ø)
components/anchor/AnchorLink.tsx 96.42% <50.00%> (-3.58%) ⬇️
components/_util/styleChecker.tsx 100.00% <100.00%> (ø)
components/badge/ScrollNumber.tsx 100.00% <100.00%> (ø)
components/badge/SingleNumber.tsx 100.00% <100.00%> (ø)
components/badge/index.tsx 100.00% <100.00%> (ø)
components/config-provider/index.tsx 100.00% <100.00%> (ø)
components/grid/col.tsx 100.00% <100.00%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8158f45...bbabf66. Read the comment docs.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 2, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bbabf66:

Sandbox Source
antd reproduction template Configuration

@afc163
Copy link
Member

afc163 commented Feb 3, 2021

Test case needed.

@delete-merged-branch delete-merged-branch bot deleted the branch ant-design:master February 16, 2021 08:34
@afc163
Copy link
Member

afc163 commented Apr 25, 2021

ping @ulion

@afc163
Copy link
Member

afc163 commented Jun 9, 2021

Closing for no response, feel free to open a new PR.

@afc163 afc163 closed this Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants