useSelectableCollection scroll-into-view anchor is incorrect when the on-screen keyboard resizes the screen after open
- Dominant language
- TypeScript
- Stars
- 15.9k
- Forks
- 1.6k
- Avg merge
- 3d 9m
- Merged PRs (30d)
- 59
Description
### Provide a general summary of the issue here
When a listbox with a selected item opens inside a mobile overlay whose input autofocused (ex. combobox in a modal sheet), the listbox's scroll-selection-into-view runs before the keyboard has opened. This leaves the selected element under the keyboard when it's all said and done
### 🤔 Expected Behavior?
The selected element should be scrolled into view regardless of if there is a keyboard or not
### 😯 Current Behavior
The selected element ends up below the keyboard
### 💁 Possible Solution
https://github.com/adobe/react-spectrum/pull/10102 seems to have implemented the canonical way to run code after keyboard opens. This same primitive can be used here. Currently `useSelectableCollection` runs a scroll into view using rAF, running one frame after the autofocus listbox shows up. This is too early for the keyboard. So rAF can be replaced with `runAfterKeyboard` and the issue will be fixed.
I have tested the proposed fix using a local copy of https://github.com/adobe/react-spectrum/pull/10102, it works
### 🔦 Context
I have a combobox inside a full height bottom sheet built on top of a modal. The mobile combobox is a button that opens a sheet which has an autofocused text input and a listbox. Reopening the combobox with a selection deep in the list is what causes this issue
### 🖥️ Steps to Reproduce
[Link to environment](https://react-aria-listbox-anchor-issue.vercel.app)
[Link to repo](https://github.com/nkalpak/react-aria-listbox-anchor-issue)
Steps to reproduce:
1. Open the environment on a mobile device, either Android or iOS
2. Click the combobox
### Version
react-aria 3.51.0 / react-aria-components 1.20.0 / react-stately 3.49.0
### What browsers are you seeing the problem on?
Other
### If other, please specify.
Safari, Chrome
### What operating system are you using?
iOS, Android
### 🧢 Your Company/Team
_No response_
### 🕷 Tracking Issue
_No response_
Contributor guide
Research direction
Start at useSelectableCollection and compare its requestAnimationFrame behavior with runAfterKeyboard from PR #10102; use the linked reproduction on mobile Safari or Chrome with a selected item in a combobox sheet. Done means the selected listbox item remains visible after the on-screen keyboard opens.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- accessibility, frontend, mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100