-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(segment-view): prevent NaN/Infinity scrollRatio when a single content item is present #31113
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,8 @@ export class SegmentView implements ComponentInterface { | |
| handleScroll(ev: Event) { | ||
| const { scrollLeft, scrollWidth, clientWidth } = ev.target as HTMLElement; | ||
| const max = scrollWidth - clientWidth; | ||
| // When only one content item is present max is 0 — skip to avoid NaN/Infinity scrollRatio. | ||
| if (max <= 0) return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The early return also skips |
||
| const scrollRatio = (isRTL(this.el) ? -1 : 1) * (scrollLeft / max); | ||
|
|
||
| this.ionSegmentViewScroll.emit({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a quick Playwright test for this in
test/basic/segment-view.e2e.ts? A singleion-segment-contentthat scrolls and assertsionSegmentViewScrolldoesn't fire (or fires with a finitescrollRatio) would lock the regression in. Without one, the next refactor ofhandleScrollcan put theNaNback silently.