fix(cascader): fix position calculation on reopening menu, closes #7321 #7350
+47
−3
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.
Description
Fix NCascader position calculation error when reopening the dropdown menu.
Closes #7321
Problem
When NCascader is positioned near the right edge of the screen:
Root Cause
The original [useOnResize] only registers the resize handler once on component mount. However, the CascaderMenu DOM is destroyed when
show=false(returnsnullin render). When reopened, a new DOM element is created but the resize handler is still bound to the old element, so expanding levels doesn't trigger [syncCascaderMenuPosition].Solution
watch(selfElRef)to re-register resize handler when DOM is recreatedtransformstyle before callingsyncPositionto ensuregetBoundingClientRectreturns correct values for position calculation