Select dropdown menu selects the first non-disabled element when no value is selected #36018
Closed
2 tasks done
Labels
component: select
This is the name of the generic UI component, not the React module!
duplicate
This issue or pull request already exists
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://stackblitz.com/edit/react-ts-5kpn2t?file=App.tsx
Steps:
Mui-selected
class applied)Current behavior 😯
When the dropdown list displays, the first non-disabled element is visually selected regardless of the actual value of the
Select
component.Important: keyboard interaction with the component works. Mentioning this, because that was one of the side effects that the regression was mitigating with selecting the first selectable item.
Expected behavior 🤔
If none of the options in the dropdown matches the
Select
component'svalue
, no item should be visually selected regardless of theirdisabled
state. Keyboard interaction with the list should still work.Context 🔦
Investigation:
This only happens under these conditions:
Select
component'svalue
is falsey.disabled
or has the value ofundefined
When both are true, the first next item in the dropdown, that has a defined value and is not disabled, will get visually selected.
This is the code from the
SelectInput.js
:Where
arr
is the array of children (=dropdownMenuItem
options), and theisFirstSelectableElement
function does this:Your environment 🌎
npx @mui/envinfo
This bug is completely envoronment/browser independent.
The text was updated successfully, but these errors were encountered: