Skip to content

Comobo box primitive: Cursor jumps to end when editing text not at the end position of combobox input #51

@Akianonymus

Description

@Akianonymus

Bug Description

When editing text in the middle of a combobox input field, the cursor automatically jumps to the end of the text instead of staying at the current position. This makes it difficult to edit text that's not at the end of the input.

Root Cause

The issue was caused by asynchronous state updates using setTimeout in the combobox primitive component:

  1. setTimeout(() => onInputValueChange(search, "inputChange"));inComboboxInput.onValueChange`
  2. setTimeout(() => onOpenChange(false)); in ComboboxItem.onSelect

These setTimeout calls delayed state updates to the next tick, causing React to re-render the component after the cursor position was already lost, resulting in the cursor jumping to the end.

For i now i just removed the setTimeout. I could just create a pr for the same but i have no idea why was setTimeout there in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions