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(cdk:popper): reference hidden popper are no longer updated #1515

Merged
merged 1 commit into from Mar 30, 2023

Conversation

sallerli1
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added/updated or not needed
  • Docs and demo have been added/updated or not needed

What is the current behavior?

reference hidden 的 popper,位置依然会被计算,此时会把浮层的位置计算到左上角

What is the new behavior?

  1. reference hidden 的 popper,位置不会再更新
  2. reference hidden 的规则,严格限定为 溢出大于0,等于0不当作被隐藏,排除了 reference display: none 的情况
  3. reference display: none 的时候,浮层不再会自动隐藏

Other information

return
}

updatePopperPosition(state)
}

let cleanUpHandler: (() => void) | null = null
Copy link

Choose a reason for hiding this comment

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

with a brief explanation of the code patch

The code patch is a piece of code from an application that provides an API for users to use. The code patch is responsible for updating the position of a "popper" element (a small component that appears when the user interacts with the application) based on the options provided by the user and the condition of the visibility element. It uses the computePosition function to calculate the position and then updates the position accordingly. Furthermore, it checks if the reference is hidden or not, and if so, it will not update the position of the popper element.

@idux-bot
Copy link

idux-bot bot commented Mar 27, 2023

This preview will be available after the AzureCI is passed.

...res.data,
referenceHidden,
},
}
},
}
}
Copy link

Choose a reason for hiding this comment

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

code review.

First of all, the code looks well structured and organized. The comments on the code also helps to understand the code better.

The code is using the hide() method from the @floating-ui/dom library and adding a new middleware called referenceHidden to add an attribute to the "floating" element when it is hidden.

There are no obvious bugs in the code, however there are some improvements that can be made.

  1. The sides array can be moved outside of the referenceHidden() function to make it more accessible and make the code easier to maintain.
  2. The referenceHiddenOffsets object can be validated to make sure that only valid sides are used.
  3. The referenceHiddenOffsets object should also be validated to make sure that the values are within the expected range.
  4. The code should also be tested to make sure that the expected behavior is working correctly.

@@ -76,7 +76,7 @@ export function usePopper<TE extends PopperElement = PopperElement, PE extends P

function initialize() {
destroy()
popperInstance = useInstance(triggerRef, popperRef, convertedOptions)
popperInstance = useInstance(triggerRef, popperRef, visibility, convertedOptions)
}

function destroy(): void {
Copy link

Choose a reason for hiding this comment

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

by looking at the diff between the two code snippets.

The change here is that a new parameter called "visibility" is being passed to useInstance. This could potentially cause bugs if this parameter isn't handled properly, or if the implementation of useInstance doesn't accept it. Additionally, it's not clear what purpose this parameter is intended to serve, so it's worth investigating why it was added to the code.

It's also important to ensure that the calling code (which is presumably outside of the snippet we're looking at) is passing the correct value for the visibility parameter. This could be done with an assertion or a check to make sure the value is valid.

Finally, it's worth considering whether the new parameter is necessary at all. If it's not being used in any way, then it may be better to remove it altogether as it could cause confusion and clutter.

@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Merging #1515 (50e9bc0) into main (703122f) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head 50e9bc0 differs from pull request most recent head 791a933. Consider uploading reports for the commit 791a933 to get more accurate results

@@            Coverage Diff             @@
##             main    #1515      +/-   ##
==========================================
+ Coverage   92.75%   92.78%   +0.03%     
==========================================
  Files         331      332       +1     
  Lines       30801    30879      +78     
  Branches     3533     3555      +22     
==========================================
+ Hits        28568    28651      +83     
+ Misses       2233     2228       -5     
Impacted Files Coverage Δ
packages/cdk/popper/src/usePopper.ts 100.00% <100.00%> (ø)
...ckages/components/_private/date-panel/src/utils.ts 100.00% <100.00%> (ø)
...ages/components/_private/selector/src/Selector.tsx 91.15% <100.00%> (+0.06%) ⬆️
packages/components/_private/selector/src/token.ts 100.00% <100.00%> (ø)
packages/components/button/src/Button.tsx 95.37% <100.00%> (ø)
packages/components/timeline/src/TimelineItem.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@danranVm danranVm merged commit 9552ef3 into IDuxFE:main Mar 30, 2023
7 checks passed
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.

None yet

2 participants