primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.45k stars 4.6k forks source link

Autocomplete virtualScroll stops working #12888

Open gunarsoskier opened 1 year ago

gunarsoskier commented 1 year ago

Describe the bug

Autocomplete stops showing suggestions when virtualScroll is enabled

Environment

https://stackblitz.com/edit/angular-j347mf?file=package.json

2023-04-14 16_03_02-PrimeNG AutocompleteVirtualScrollDemo - StackBlitz

Reproducer

No response

Angular version

15.2.5

PrimeNG version

15.3.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

16.19.0

Browser(s)

Chrome 111

Steps to reproduce the behavior

in this demo https://stackblitz.com/edit/angular-j347mf?file=package.json

  1. write to input "item" - suggestions are shown
  2. empty input
  3. write text that is not in the suggestions (for example '000'
  4. empty input
  5. write to input "item" - suggestions are empty

Expected behavior

suggestions are shown

DonITproject commented 1 year ago

Yes, there really is such a problem. This works especially badly in conjunction with lazy. Of course, I can make edits myself, but I don't want to override yet another PrimeNg component

FabianAhammer commented 1 year ago

Same issue here, is there any plan on the fix for this?

martinboue commented 1 year ago

Same problem with v15.4.1, I tried to investigate a little and here is what I found:

In the following method, if this.contentEl is not currently rendered in the DOM, which is the case after filtering with a text that is NOT in the suggestions, this.contentEl is truthy and we will not fallback to default styles. In this case, left, right, top and bottom will be NaN https://github.com/primefaces/primeng/blob/1b589dbca296d80eb24b0450ccc591746fcb0762/src/app/components/scroller/scroller.ts#L823-L835

This NaN is propagated from getContentPosition to calculateNumItems then calculateOptions method, where numItemsInViewport will be NaN which will result to this.last being NaN too. https://github.com/primefaces/primeng/blob/1b589dbca296d80eb24b0450ccc591746fcb0762/src/app/components/scroller/scroller.ts#L767-L793

Because this.last is NaN, the following method responsible for getting all the items to show will return an empty array (this._items.slice(0, NaN) returns []). That's why no suggestions are rendered. https://github.com/primefaces/primeng/blob/1b589dbca296d80eb24b0450ccc591746fcb0762/src/app/components/scroller/scroller.ts#L484-L492

TLDR; root cause seems to be getContentPosition method in scroller component that returns NaN for all directions.

ashikjs commented 1 year ago

Can you check Primeng 16.3.0. I checked it's already solved.

https://primeng.org/autocomplete#virtualscroll

lixaotec commented 1 year ago

its not

gunarsoskier commented 11 months ago

I tried 16.8.0 and after step 5. it is now showing options but dropdown shrinks to 30px