Skip to content

[autocomplete] ArrowLeft throws error if value not set when single value rendering is used #47212

@wjwat

Description

@wjwat

Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/github-dy1275cl?file=src%2FApp.tsx
  2. With either of the Autocomplete fields in focus press ArrowLeft
    1. This happens if there is input text in the field or not as long as no value has been set.
  3. Observe error in console.

This is reproducible on the doc site as well with the same steps: https://mui.com/material-ui/react-autocomplete/#single-value-rendering

Uncaught TypeError: can't access property "focus", anchorEl.querySelector(...) is null
    focusItem @mui_material_Autocomplete.js:278
    useEventCallback chunk-KPQAQXG2.js:35
    handleKeyDown @mui_material_Autocomplete.js:717
    executeDispatch react-dom_client.js:13620
    runWithFiberInDEV react-dom_client.js:997
    processDispatchQueue react-dom_client.js:13656
    dispatchEventForPluginEventSystem react-dom_client.js:14069
    batchedUpdates$1 react-dom_client.js:2624
    dispatchEventForPluginEventSystem react-dom_client.js:13761
    dispatchEvent react-dom_client.js:16782
    dispatchDiscreteEvent react-dom_client.js:16763
    addTrappedEventListener react-dom_client.js:13726
    listenToNativeEvent react-dom_client.js:13685
    listenToAllSupportedEvents react-dom_client.js:13696
    listenToAllSupportedEvents react-dom_client.js:13695
    createRoot react-dom_client.js:20131
    <anonymous> main.tsx:5
3 @mui_material_Autocomplete.js:278:16

Current behavior

An error is thrown.

Expected behavior

No error is thrown.

Context

No response

Your environment

Search keywords: arrowleft autocomplete typeerror "cannot read property focus"

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGreat for first contributions. Enable to learn the contribution process.scope: autocompleteChanges related to the autocomplete. This includes ComboBox.type: bugIt doesn't behave as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions