Skip to content
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

Scroller: When itemSize is not set, scrolling to top results in component crash #15395

Closed
prx-lmo opened this issue Apr 29, 2024 · 0 comments · Fixed by #15396
Closed

Scroller: When itemSize is not set, scrolling to top results in component crash #15395

prx-lmo opened this issue Apr 29, 2024 · 0 comments · Fixed by #15396
Labels
LTS-PORTABLE Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@prx-lmo
Copy link
Contributor

prx-lmo commented Apr 29, 2024

Describe the bug

When the property [itemSize] is not set in the html component, scrolling to top results in component crash. The scroller doesn't get shown anymore.
The reason for that is that these lines result in a NaN, because they divide by zero.

const calculateCurrentIndex = (_pos: number, _size: number) => Math.floor(_pos / (_size || _pos));

const calculateNumItemsInViewport = (_contentSize: number, _itemSize: number) => Math.ceil(_contentSize / (_itemSize || _contentSize));

const calculateFirstInViewport = (_pos: number, _size: number) => Math.floor(_pos / (_size || _pos));

There are as far as I can tell, three possible fixes:

  • simply prevent these lines from dividing by zero
  • calculate the itemSize, either in the getter or a new function, by dividing item count by component length
  • make itemSize required(worst option)

Environment

tested with Chrome and Firefox

Reproducer

No response

Angular version

17.3.6

PrimeNG version

17.15.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.11.1

Browser(s)

No response

Steps to reproduce the behavior

write a component like this

  1. <p-scroller [items]="itemList" [autoSize]="true" [scrollHeight]="200px"> bla </p-scroller>
  2. scroll a bit down
  3. scroll to top

Expected behavior

well... component should'nt break

@prx-lmo prx-lmo added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 29, 2024
@cetincakiroglu cetincakiroglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working LTS-PORTABLE and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels May 3, 2024
@cetincakiroglu cetincakiroglu added this to the 17.16.0 milestone May 3, 2024
cetincakiroglu added a commit that referenced this issue May 3, 2024
Bug #15395 - prevent division by zero Errors in Scroller when no itemSize provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-PORTABLE Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants