nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Autocomplete section overlap due to incorrect `itemHeight` with virtualization

Open thatkev opened this issue 1 year ago • 7 comments

NextUI Version

2.6.11

Describe the bug

AutocompleteSection, when containing too many AutocompleteItems, seems to have the category text (and occasional items) overlap. This behaviour is pertinent to all tested major browsers (Chromium-based browsers, Safari, Firefox).

Your Example Website or App

https://stackblitz.com/~/github.com/thatkev/autocomplete-bug https://github.com/thatkev/autocomplete-bug

Steps to Reproduce the Bug or Issue

  1. Start dev server, visit the root page.
  2. Click the dropdown, scroll and observe the bug.

Expected behavior

I expect that AutocompleteSection and AutocompleteItem are appropriately spaced, and do not overlap.

Screenshots or Videos

image image

Operating System Version

macOS Sequoia 15.3 Beta (24D5034f)

Browser

Chrome

thatkev avatar Jan 16 '25 00:01 thatkev

@wingkwong please check

jrgarciadev avatar Jan 19 '25 00:01 jrgarciadev

Issue cause has been pinpointed to virtualization- disabling it resolves the issue.

thatkev avatar Jan 19 '25 02:01 thatkev

@jrgarciadev Please assign it to me!

GuntreddyHemanth avatar Feb 05 '25 16:02 GuntreddyHemanth

The issue occurs because an incorrect itemHeight is being passed during virtualization.
https://github.com/heroui-inc/heroui/blob/a1cc37888747a551d9dc5b2f53a1d32d839d2553/packages/components/autocomplete/src/use-autocomplete.ts#L460-L464

Since startContent dynamically changes the list height, the correct itemHeight must be provided.

https://github.com/user-attachments/assets/e6124c4e-081f-43c3-932b-817a7a511175


I’ll update the docs to note that startContent with virtualization requires the correct itemHeight.

Just a side note, I also tried dynamically measuring the list item height and applying it to the virtualizer, but it didn’t work as expected... 😓

ryo-manba avatar Feb 11 '25 07:02 ryo-manba

@ryo-manba What if not all items have startContent? Won’t this throw off the formatting?

thatkev avatar Feb 11 '25 07:02 thatkev

As it stands, the only option is to set isVirtualized={false}.

ryo-manba avatar Feb 11 '25 13:02 ryo-manba