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(module:overlay): getFirstChildDomInfo will return passed dom instead of body when no child element exists #989

Merged

Conversation

anddrzejb
Copy link
Member

🤔 This is a ...

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

🔗 Related issue link

#873

💡 Background and solution

The bug was appearing in Dropdown when ChildContent was not an element but a simple text:

<ChildContent>
    Dropdown 
</ChildContent>

Here, "Dropdown" is not an element. If it was wrapped in (for example) <span>, this bug would not surface.
The problem here is that the underlying Overlay is trying to get Childcontent's first child. By default with current approach child content is wrapped in a div - so Overlay will try to get div's first child. If there is no element inside (for "Dropdown" there is no element), the Overlay will be delivered <body> element.

The fix is to check if first child is null and when it is, then just return the passed element (for that issue it will be div).

Possible issues
This is a quick fix. The getFirstChildDomInfo is only used by Overlay and OverlayTrigger. It does not really return what it promises based on its name. Currently it either returns (correctly) first child of the passed dom element or top parent (<body>). With this PR, it will either return first child of the passed dom element or the dom element itself. It probably should return null, but that would require much more code changes. The possible issues comes from naming - what will a consumer expect and how will current/proposed resolution match/miss consumer's expectations.

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self Check before Merge

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

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Changelog is provided or not needed

getFirstChildDomInfo returns passed domInfo when dom.firstElementChild is null
fixes ant-design-blazor#837
@codecov-io
Copy link

Codecov Report

Merging #989 (d8662fc) into master (86afda3) will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #989      +/-   ##
=========================================
- Coverage    5.73%   5.72%   -0.01%     
=========================================
  Files         406     406              
  Lines       21823   21823              
=========================================
- Hits         1252    1250       -2     
- Misses      20571   20573       +2     
Impacted Files Coverage Δ
components/tabs/Tabs.razor.cs 55.51% <0.00%> (-0.82%) ⬇️

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 86afda3...d8662fc. Read the comment docs.

Copy link
Member

@ElderJames ElderJames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It helps a lot

@ElderJames ElderJames merged commit 9a78f9a into ant-design-blazor:master Jan 17, 2021
@anddrzejb anddrzejb deleted the getFirstChildDomInfoWhenNull branch January 17, 2021 07:44
ElderJames pushed a commit that referenced this pull request Apr 23, 2022
…null (#989)

getFirstChildDomInfo returns passed domInfo when dom.firstElementChild is null
fixes #837
ElderJames pushed a commit that referenced this pull request Apr 30, 2022
…null (#989)

getFirstChildDomInfo returns passed domInfo when dom.firstElementChild is null
fixes #837
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dropdown's overlay rendered with wrong top and left value but the dropdown button works
3 participants