adobe / adobe/react-spectrum

TreeView: On touch devices, when disallowEmptySelection is enabled, the TreeView component does not revert to selectionBehavior="replace" as expected

Open
#8,709 3 comments 1 reaction 0 assignees View on GitHub
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

Hi, I noticed something potentially unintended regarding the behavior described in the [TreeView documentation](https://react-spectrum.adobe.com/react-aria/Tree.html#item-actions):

On the docs -> On touch devices, the action becomes the primary tap interaction, and a long press enters into selection mode, which temporarily swaps the selection behavior to "toggle" to perform selection (you may wish to display checkboxes when this happens). Deselecting all items exits selection mode and reverts the selection behavior back to "replace".

However, when using disallowEmptySelection, it's not possible to deselect all items—meaning the TreeView never exits selection mode, and thus never reverts back to selectionBehavior="replace".

This leads to inconsistent behavior on touch devices when disallowEmptySelection is enabled, as the temporary selection mode becomes effectively permanent. It also causes the onAction to not be triggered.

Would love to know if this is the intended behavior, or if a workaround is recommended in this scenario

### 🤔 Expected Behavior?

When disallowEmptySelection is enabled:

The TreeView should still be able to exit selection mode, even though it prevents a completely empty selection.

For example, exiting selection mode could occur after the user performs a tap (primary action) or long press on a selected item—without requiring the selection to be empty.

Once selection mode is exited, selectionBehavior should revert to "replace" so that single-tap actions behave as expected again.

### 😯 Current Behavior

When disallowEmptySelection is enabled:

The TreeView enters selection mode as expected on long press.

However, because at least one item must remain selected, the user can never fully deselect all items.

As a result, the TreeView never exits selection mode, and selectionBehavior remains stuck in "toggle" mode.

This leads to a permanent change in interaction behavior, breaking the expected revert to "replace" and causing the onAction passed to the TreeView to not be called.

### 💁 Possible Solution

_No response_

### 🔦 Context

_No response_

### 🖥️ Steps to Reproduce

```
import { Tree, TreeItem, TreeItemContent } from "react-aria-components";

export function TreeView() {
return (


Item 1


Item 2


);
}
```

### Version

react-aria: ^3.40.0 react-aria-components: 1.9.0

### What browsers are you seeing the problem on?

Chrome

### If other, please specify.

_No response_

### What operating system are you using?

macOS Sequoia 15.6

### 🧢 Your Company/Team

_No response_

### 🕷 Tracking Issue

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.