Skip to content

fix(components): [tabs] incorrect boundary detection when container size is a float number#23774

Merged
btea merged 1 commit into
devfrom
fix/23773
Mar 11, 2026
Merged

fix(components): [tabs] incorrect boundary detection when container size is a float number#23774
btea merged 1 commit into
devfrom
fix/23773

Conversation

@rzzf
Copy link
Copy Markdown
Member

@rzzf rzzf commented Mar 11, 2026

fix #23773

Summary by CodeRabbit

  • Bug Fixes
    • Improved scrolling detection in tabs navigation by using more accurate size measurements. This ensures scroll controls appear correctly when tab content exceeds available space.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 11, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

Modifies tab navigation component to measure container and navigation sizes using DOMRect-based values from getBoundingClientRect() instead of integer offset properties, enabling accurate scroll endpoint detection with fractional pixel tab widths.

Changes

Cohort / File(s) Summary
Tab Navigation Measurement
packages/components/tabs/src/tab-nav.tsx
Replaced offsetWidth/offsetHeight measurements with getBoundingClientRect()[width|height] for navSize and containerSize to properly account for fractional pixel widths in scroll overflow calculations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

Needs Review

Suggested reviewers

  • Dsaquel

Poem

🐰 Fractional pixels danced in sight,
DOMRect brings the truth to light,
No more misaligned ends in sight,
The arrow knows when we're just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description is minimal ('fix #23773') but references the linked issue, which is acceptable in this repository's template context.
Linked Issues check ✅ Passed The code change replaces offsetWidth/offsetHeight with getBoundingClientRect()[width|height] to handle fractional container sizes, directly addressing issue #23773's requirement for floating-point epsilon tolerance in boundary detection.
Out of Scope Changes check ✅ Passed All changes in tab-nav.tsx are directly related to fixing the boundary detection issue for fractional container sizes as specified in issue #23773.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The pull request title accurately describes the main change: fixing incorrect boundary detection when container size is a float number, which directly addresses the core issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/23773

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the CommitMessage::Unqualified Unqualified commit message label Mar 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 11, 2026

Hello, @rzzf, your PR title does not meet the standards, please refer to here.
你好,@rzzf,你的 PR 标题不符合规范,请参考这里

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 11, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/element-plus@23774
npm i https://pkg.pr.new/element-plus@23774
yarn add https://pkg.pr.new/[email protected]

commit: 7262caa

@rzzf rzzf changed the title fix(components): [tab] incorrect boundary detection when container size is a decimal fix(components): [tab] incorrect boundary detection when container size is a float number Mar 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Size Change: +40 B (0%)

Total Size: 1.45 MB

Filename Size Change
./dist/element-plus/dist/index.full.js 427 kB +14 B (0%)
./dist/element-plus/dist/index.full.min.js 283 kB +7 B (0%)
./dist/element-plus/dist/index.full.min.mjs 276 kB +5 B (0%)
./dist/element-plus/dist/index.full.mjs 418 kB +14 B (0%)
ℹ️ View Unchanged
Filename Size
./dist/element-plus/dist/index.css 46.8 kB

compressed-size-action

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 | 🟠 Major

Add 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. If navOffset.value lands at maxOffset - ε, scrollable.value.next stays enabled and the extra-click behavior can still reproduce. Compare the remaining distance against a small pixel epsilon and snap to maxOffset once 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

📥 Commits

Reviewing files that changed from the base of the PR and between d5c8de0 and 91946b8.

📒 Files selected for processing (1)
  • packages/components/tabs/src/tab-nav.tsx

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 85.58% 18086 / 21132
🔵 Statements 84.37% 18934 / 22441
🔵 Functions 83.45% 4834 / 5792
🔵 Branches 74.06% 10450 / 14109
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/components/tabs/src/tab-nav.tsx 61.01% 44.85% 54.76% 62.5% 54, 93, 133, 136, 141, 143, 146, 150-154, 159, 159, 162-163, 165, 165, 168, 170, 174, 174, 176, 178-179, 181, 181, 184-186, 188, 195, 197-198, 198, 200, 202-206, 211-214, 212-213, 215-218, 216-217, 220-223, 221-222, 224-228, 225-227, 230-231, 235, 245-250, 249, 254, 273, 308, 310-311, 315-319, 316-319, 318, 318, 322-326, 323, 323, 325, 330, 353, 364, 417-418, 429
Generated in workflow #1792

@github-actions
Copy link
Copy Markdown
Contributor

🧪 Playground Preview: https://element-plus.run/?pr=23774
Please comment the example via this playground if needed.

@btea btea merged commit 1a484aa into dev Mar 11, 2026
18 checks passed
@btea btea deleted the fix/23773 branch March 11, 2026 02:50
@github-actions
Copy link
Copy Markdown
Contributor

@rzzf Thanks for your contribution! ❤️

@rzzf rzzf changed the title fix(components): [tab] incorrect boundary detection when container size is a float number fix(components): [tabs] incorrect boundary detection when container size is a float number Mar 11, 2026
@element-bot element-bot mentioned this pull request Mar 20, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CommitMessage::Unqualified Unqualified commit message

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Style] [tab-pane, tabs] el-tabs nav-next arrow not disabled at end when tab widths are fractional

2 participants