Skip to content

Combobox not showing input value when using e defaultSelectedKey and autofocus #9389

Open

Description

@snowystinger

Discussed in #9387

Originally posted by francescosac95 December 22, 2025
Hey everyone,

I am using Combobox from react aria components and I am running into an issue (Uncontrolled component).
The issue is when I have the combobox on autofocus and I have a defaultSelected key, the input value is empty. When I blur out I can see the right input value for the default selected key.
When I remove the autofocus everything works as expected, on initial render I can see the default selected key with the right input value.
Am I missing something? Is this how it's supposed to be working or is it a bug?

Reproduction https://stackblitz.com/edit/j8e97chh?file=src%2FExample.tsx

Activity

  1. LFDanLu commented on Dec 22, 2025

    @LFDanLu
    Member

    I believe this is due to the nature of autoFocus and the 2 render pass that RAC collections need to build. The moment

    // Update the inputValue if the selected item's text changes from its last tracked value.
    // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.
    // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
    // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
    let selectedItemText = selectedKey != null ? collection.getItem(selectedKey)?.textValue ?? '' : '';
    if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
    if (lastSelectedKeyText.current !== selectedItemText) {
    setLastValue(selectedItemText);
    setInputValue(selectedItemText);
    }
    runs and the input field is NOT yet focused but autoFocus, we'd ideally have a input value from the selected key, but the collection isn't available yet. In subsequent renders, the field is already focused which means we won't overwrite the input field's value as per the above code comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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