Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/components/segment-view/segment-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Member

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 single ion-segment-content that scrolls and asserts ionSegmentViewScroll doesn't fire (or fires with a finite scrollRatio) would lock the regression in. Without one, the next refactor of handleScroll can put the NaN back silently.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The early return also skips resetScrollEndTimeout(). If setContent set isManualScroll = false and started the timer, then a scroll event lands in the max <= 0 branch, the timer doesn't get extended on this event and isManualScroll could clear early. I think it's fine in practice since a non-overflowing element shouldn't really fire scroll events, but worth a sanity check to just go ahead and resetScrollEndTimeout in the if body.

const scrollRatio = (isRTL(this.el) ? -1 : 1) * (scrollLeft / max);

this.ionSegmentViewScroll.emit({
Expand Down
Loading