[autocomplete] ArrowLeft throws error if value not set when single value rendering is used
Steps to reproduce
Steps:
- Open this link to live example: https://stackblitz.com/edit/github-dy1275cl?file=src%2FApp.tsx
- With either of the Autocomplete fields in focus press ArrowLeft
- This happens if there is input text in the field or not as long as no value has been set.
- 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"
Related: https://github.com/mui/material-ui/issues/27933
Thanks for reporting. It's a bug. Open for contribution from the community. If you pick this up, please also add a test case.
Hi @ZeeshanTamboli , I will be happy to pick this issue. Should I work on it ?
I have started working on the issue.
@rithik56 Feel free to create a PR.
@ZeeshanTamboli I have opened the PR. Please review this
@ZeeshanTamboli I’d like to take this issue on.
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.