material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

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

Open wjwat opened this issue 3 months ago • 7 comments

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"

wjwat avatar Nov 07 '25 22:11 wjwat

Related: https://github.com/mui/material-ui/issues/27933

wjwat avatar Nov 07 '25 22:11 wjwat

Thanks for reporting. It's a bug. Open for contribution from the community. If you pick this up, please also add a test case.

ZeeshanTamboli avatar Nov 08 '25 07:11 ZeeshanTamboli

Hi @ZeeshanTamboli , I will be happy to pick this issue. Should I work on it ?

rithik56 avatar Nov 08 '25 07:11 rithik56

I have started working on the issue.

rithik56 avatar Nov 08 '25 07:11 rithik56

@rithik56 Feel free to create a PR.

ZeeshanTamboli avatar Nov 08 '25 08:11 ZeeshanTamboli

@ZeeshanTamboli I have opened the PR. Please review this

rithik56 avatar Nov 08 '25 09:11 rithik56

@ZeeshanTamboli I’d like to take this issue on.

Ajith27887 avatar Nov 09 '25 18:11 Ajith27887

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

github-actions[bot] avatar Nov 11 '25 11:11 github-actions[bot]