fix(components): [tabs] incorrect boundary detection when container size is a float number#23774
Conversation
📝 WalkthroughWalkthroughModifies tab navigation component to measure container and navigation sizes using DOMRect-based values from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hello, @rzzf, your PR title does not meet the standards, please refer to here. |
commit: |
|
Size Change: +40 B (0%) Total Size: 1.45 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/components/tabs/src/tab-nav.tsx (1)
239-249:⚠️ Potential issue | 🟠 MajorAdd an epsilon when deciding the end state.
Switching to
getBoundingClientRect()fixes the integer rounding, but Line 247 and Line 248 still depend on exact equality. IfnavOffset.valuelands atmaxOffset - ε,scrollable.value.nextstays enabled and the extra-click behavior can still reproduce. Compare the remaining distance against a small pixel epsilon and snap tomaxOffsetonce it falls under that threshold.Suggested adjustment
const currentOffset = navOffset.value + const edgeEpsilon = 0.5 if (containerSize < navSize) { + const maxOffset = navSize - containerSize + const remaining = maxOffset - currentOffset + const atEnd = remaining <= edgeEpsilon scrollable.value = scrollable.value || {} scrollable.value.prev = currentOffset - scrollable.value.next = currentOffset + containerSize < navSize - if (navSize - currentOffset < containerSize) { - navOffset.value = navSize - containerSize + scrollable.value.next = !atEnd + if (atEnd) { + navOffset.value = maxOffset } } else {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/components/tabs/src/tab-nav.tsx` around lines 239 - 249, The end-state check should allow a small pixel epsilon to avoid floating/rounding issues: compute maxOffset = navSize - containerSize and remaining = maxOffset - navOffset.value (or remaining = navSize - containerSize - navOffset.value), then if remaining <= EPSILON (e.g., 1) set navOffset.value = maxOffset and set scrollable.value.next = false; also use remaining > EPSILON when setting scrollable.value.next earlier so it disables when within the epsilon. Update the logic around navSize, containerSize, navOffset, scrollable, nav$, and navScroll$ accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/components/tabs/src/tab-nav.tsx`:
- Around line 239-249: The end-state check should allow a small pixel epsilon to
avoid floating/rounding issues: compute maxOffset = navSize - containerSize and
remaining = maxOffset - navOffset.value (or remaining = navSize - containerSize
- navOffset.value), then if remaining <= EPSILON (e.g., 1) set navOffset.value =
maxOffset and set scrollable.value.next = false; also use remaining > EPSILON
when setting scrollable.value.next earlier so it disables when within the
epsilon. Update the logic around navSize, containerSize, navOffset, scrollable,
nav$, and navScroll$ accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 88296485-e1b3-4132-817b-744cb9dbd8c8
📒 Files selected for processing (1)
packages/components/tabs/src/tab-nav.tsx
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
|
🧪 Playground Preview: https://element-plus.run/?pr=23774 |
|
@rzzf Thanks for your contribution! ❤️ |

fix #23773
Summary by CodeRabbit