ComboBox list items not scrolling
Provide a general summary of the issue here
I am integrating comboBox with my React app, React - v18 Node - v20.7.0 OS - Ubuntu 22.04.4 LTS
"@adobe/react-spectrum": "^3.34.1",
"@react-spectrum/combobox": "^3.12.3",
"@react-spectrum/provider": "^3.9.5",
https://github.com/adobe/react-spectrum/assets/43287621/bb3c03d0-d057-44b3-b541-b13c841104ef
๐ค Expected Behavior?
Should be able to scroll the items in the list box
๐ฏ Current Behavior
Unable to scroll items in list box
๐ Possible Solution
No response
๐ฆ Context
No response
๐ฅ๏ธ Steps to Reproduce
- Clone the repo - https://github.com/upender7270/react-combobox
-
yarn -
yarn storybook - Open dynamic or static story of the combobox
Version
3.34.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
Ubuntu
๐งข Your Company/Team
No response
๐ท Tracking Issue
No response
Yah yah I've also faced this issue many times. Someone please look into this.
Possibly related scrollIntoViewport: improve scrolling behavior for elements with multiple scrollable parents
@snowystinger just tested with the nightly and I still saw this issue, so seems unrelated.
I was also looking into this issue at the moment, and realized PopoverWrapper was being rendered too many times (this can be verified with React Developer Tools). And this infinite rendering of <PopoverWrapper> seems to be the reason why we're unable to scroll.
It looks like the root cause of this chain rendering is the invocation of updatePosition() inside the onResize() callback here:
https://github.com/adobe/react-spectrum/blob/72775d272be04cfa32d26ec821bc68513d92a72b/packages/%40react-aria/overlays/src/useOverlayPosition.ts#L195-L204
If the above updatePosition() is commented out, you'll see the working scroll:
https://github.com/adobe/react-spectrum/assets/71210554/46a0c1ea-64bc-4682-9f0b-9132e0bf6692
Update
Might be related to https://github.com/adobe/react-spectrum/issues/5653#issuecomment-2014972059 in terms of the change in behavior of resize event of VisualViewport.
I'm experiencing the same issue. When the list is long enough and a scrollbar is rendered, the resize event from VisualViewport is triggered very often causing updatePosition to be called very often as well. This in turn causes the list to be unscrollable. It does not seem to be related to scrolling itself, since the resize event is triggering right after opening the ComboBox (see my second recording).
So far, I've only seen this happen when shouldFlip is set to false and isNonModal is set to true in ComboBox (as @sookmax already brought up in another issue). Setting shouldFlip to true (default behavior) or isNonModal to false doesn't seem to result in the repeated resize events.
Setting a fixed max-height on ListBox seems to fix the repeated resize events as well, but that causes the list to overflow the popover and trying to circumvent this through overflow-y either causes double scrollbars or parts of ListBox being hidden.
This recording shows scroll state resetting:
https://github.com/adobe/react-spectrum/assets/101109442/3c36bcb0-4f86-44a5-992c-e6feff4d2762
And this recording shows a console.log whenever resize is triggered on visualViewport.
https://github.com/adobe/react-spectrum/assets/101109442/caac9ca8-b2e5-40c7-af44-b18f293ee8e2
If it helps, I've noticed that rolling back one version to 3.33.1 fixes it, so it must have been introduced by a commit between that and 3.34.0.
Another thing I noticed was it only happens if the parent doesn't contain enough space to fit the list, so for example:
Works:
<View height="4000px"> // height bigger than list
<ComboBox
label="test"
items={Array.from({ length: 200 }, (_, index) => ({
name: `Item ${index}`,
key: index,
}))}
>
{(item) => <Item>{item.name}</Item>}
</ComboBox>
</View>
Doesn't work:
<View height="1000px"> // height smaller than list
<ComboBox
label="test"
items={Array.from({ length: 200 }, (_, index) => ({
name: `Item ${index}`,
key: index,
}))}
>
{(item) => <Item>{item.name}</Item>}
</ComboBox>
</View>
Looks like we broke this in https://github.com/adobe/react-spectrum/pull/5808
This is now fixed in the latest patch release.