Skip to content

Combobox selects the active value when the focus is moved away #2934

@tobia

Description

@tobia

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

Both 1.7.18 and 0.0.0-insiders.3b961a6

What browser are you using?

Firefox, Chrome

Reproduction URL

This can be easily reproduced on the demo page: https://headlessui.com/react/combobox

Describe your issue

  1. Open the demo page https://headlessui.com/react/combobox
  2. Click on the double-arrow button to open the list.
  3. Use the keyboard to navigate the list, for instance hitting Down a couple times: this will change the active item, but not the selected item.
  4. Do *not select the item with either Enter or Click, instead use Tab to move out of the field.

Expected behaviour: the field's selected value should remain unchanged.

Actual behaviour: the item that was active in the menu gets selected as the field value.

This is particularly problematic with the new immediate option available in the insiders release, because now you can alter the field values just by Tabbing through a form.

This is because as soon as the focus enters a Combobox in immediate mode, the menu of options is made visible and the first item is automatically made active, then hitting Tab again selects the active item, thus changing the value of the field.

Proposed solution: the active item should become selected only when a specific set of events occur, namely mouse Click or Enter key.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions