adobe / adobe/react-spectrum

[RAC] ComboBox onSelectionChange not consistent with click and keypress

Open
#6,837 5 comments 0 reactions 0 assignees View on GitHub
enhancement
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

ComboBox `onSelectionChange` works differently with mouse click and keyboard. When I reselect the selected item by clicking with a mouse, `onSelectionChange` is fired every time. However when I do the same using keyboard by pressing Enter, the event is not fired on consecutive selections.

### 🤔 Expected Behavior?

I'd expect `onSelectionChange` to be fired each time like the mouse click to have a consistent behavior.

### 😯 Current Behavior

`onSelectionChange` is not fired on consecutive selects when an item is reselected using keyboard.

### 💁 Possible Solution

_No response_

### 🔦 Context

I'm working on a searchable menu component where we want the component to work as a searchable select as well as a menu, to trigger an event when an item is clicked. So there'll be no selection with menu behavior and a user should be able to fire the `onSelectionChange` when clicking on the same item next time.

### 🖥️ Steps to Reproduce

Please go to https://stackblitz.com/edit/vitejs-vite-eqeusx?file=src%2FApp.tsx
1. Open console
2. Select an item in the ComboBox by a mouse click.
3. Select the same item again a few times. Every time you select the same item, you can see `onSelectionChange` logs the selection in the console.
4. Select an item using keyboard only `onSelectionChange` logs the selection.
5. Select the same item using the keyboard and nothing will be logged to console.

### Version

react-aria-components 1.3.1

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

Firefox, Chrome, Safari, Other

### If other, please specify.

Brave

### What operating system are you using?

MacOS

### 🧢 Your Company/Team

Hygraph / Baukasten Design System

### 🕷 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.