Weird behavior of extending selection in a multi selectable list
- 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
From [discussion](https://github.com/adobe/react-spectrum/discussions/4947):
> Hi, I wanted to ask about expected behavior of the [extendSelection](https://github.com/adobe/react-spectrum/blame/8987f9283871b1bda0acc4637096966275f82167/packages/%40react-stately/selection/src/SelectionManager.ts#L207) method.
>
> As a live example I will use [this code sandbox](https://codesandbox.io/s/lucid-fire-mf0m6j?file=/src/App.js).
>
> Reproduction steps:
>
> 1. Select "Games" with Space
> 2. Unselect "Games" with Space
> 3. Press down arrow 2 times, to move to "bootmgr"
> 4. Hold Shift and press down arrow.
>
> **Expected:** "bootmgr" and "log.txt" will be selected **Actual:** All rows are selected.
>
> More precisely, I think the question is whether the `anchorKey` should work the same when there are no selected rows. For me, it is a bit confusing to see all rows being selected.
>
> Wanted to know your thoughts about this and to know if there's a particular reason it works like this.
>
> Thanks!
### 🤔 Expected Behavior?
`anchorKey` should be set to the `focusedKey` when the shift key is pressed.
### 😯 Current Behavior
`anchorKey` is the last selected item
### 💁 Possible Solution
Address _anchorKey should be set to the focusedKey when the shift key is pressed_
### 🔦 Context
_No response_
### 🖥️ Steps to Reproduce
https://codesandbox.io/s/lucid-fire-mf0m6j?file=/src/App.js
1. Select "Games" with Space
2. Unselect "Games" with Space
3. Press down arrow 2 times, to move to "bootmgr"
4. Hold Shift and press down arrow.
5. **Expected:** "bootmgr" and "log.txt" will be selected **Actual:** All rows are selected.
### Version
latest
### What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Microsoft Edge
### If other, please specify.
_No response_
### What operating system are you using?
MacOS
### 🧢 Your Company/Team
_No response_
### 🕷 Tracking Issue
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.