Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Select] Shows the first item to be selected when initial value is blank or null and the menu popover is not aligned properly with the Select #32407

Open
2 tasks done
anuraggo opened this issue Apr 21, 2022 · 9 comments
Labels
bug 🐛 Something doesn't work component: select This is the name of the generic UI component, not the React module!

Comments

@anuraggo
Copy link

anuraggo commented Apr 21, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

image

Trying to create a simple basic Select with no customization / or styling.
Two issues observerd --

  • As shown in picture, the first item 'Ten' is shown kind of selected gray background. However, I didn't hover or clicked inside the menu.
  • The menu popover has incorrectly aligned left positions w.r.t Select.

Please help.
Below is the code snipped used --

import * as React from 'react';
import MenuItem from '@mui/material/MenuItem';
import Select, { SelectChangeEvent } from '@mui/material/Select';

export default function SelectLabels() {
  const [age, setAge] = React.useState('');
  const handleChange = (event: SelectChangeEvent) => {
    setAge(event.target.value);
  };
  
  return (
    <div>
      <Select
        labelId="demo-simple-select-helper-label"
        id="demo-simple-select-helper"
        value={age}
        onChange={handleChange}
        sx={{ minWidth: 120 }}
      >
        <MenuItem value={10}>Ten</MenuItem>
        <MenuItem value={20}>Twenty</MenuItem>
        <MenuItem value={30}>Thirty</MenuItem>
      </Select>
    </div>
  );
}

Expected behavior 🤔

No response

Steps to reproduce 🕹

Steps:

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@anuraggo anuraggo added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 21, 2022
@anuraggo anuraggo changed the title Select shows the first item to be selected when initial value is blank or null. Select shows the first item to be selected when initial value is blank or null and the menu popover is not aligned properly with the Select. Apr 21, 2022
@danilo-leal danilo-leal changed the title Select shows the first item to be selected when initial value is blank or null and the menu popover is not aligned properly with the Select. [Select] Shows the first item to be selected when initial value is blank or null and the menu popover is not aligned properly with the Select Apr 26, 2022
@danilo-leal danilo-leal added the component: select This is the name of the generic UI component, not the React module! label Apr 26, 2022
@michaldudak
Copy link
Member

The darker background indicates a highlighted item - that is, the one that will get selected when you press Enter.
As for the misalignment - it does look like a bug. Would you be interested in investigating it and working on a fix?

@michaldudak michaldudak added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 24, 2022
@NicoSan20
Copy link

@michaldudak : Same issue here ! The first item is selected when initial value is blank or null. And this happen without pressing enter as you claim.

@michaldudak
Copy link
Member

I didn't mean you need to press Enter. I'm saying that the first item is highlighted, which means it'll be selected after a user presses Enter. This is by design.

@michaldudak michaldudak removed their assignment Nov 21, 2022
@immortalt
Copy link

immortalt commented Mar 21, 2023

Same issue here! This problem can be triggered when running https://mui.com/material-ui/react-app-bar/#app-bar-with-menu on iOS (16.3.1 latest) and Safari (latest). The first menu item would be gray after the menu appeared.

@NenadBecanovicPD
Copy link

I didn't mean you need to press Enter. I'm saying that the first item is highlighted, which means it'll be selected after a user presses Enter. This is by design.

@michaldudak You are right, but the highlighted first item is not clickable so it can't be chosen by click but only by Enter.

@LeeSolfmk
Copy link

@michaldudak I have same opinion as @NenadBecanovicPD. This issue is torturing my designer and me.. please let us know as least how to disable that option, either with api option or with css id.

@michaldudak
Copy link
Member

the highlighted first item is not clickable so it can't be chosen by click but only by Enter.

@NenadBecanovicPD, what do you mean by not clickable?

@LeeSolfmk, how would you like to indicate the currently highlighted item, then?

You can target the highlighted item using the .Mui-focusVisible CSS class, but if you remove the highlight it will become inaccessible by the keyboard.

@michael-lynch
Copy link

You should be able to disable autoFocus on the <Menu>.

<Select
  MenuProps: {{
    autoFocus: false
  }}
/>

https://mui.com/material-ui/api/select/#Select-prop-MenuProps
https://mui.com/material-ui/api/menu/#Menu-prop-autoFocus

@fatemehqasemkhani
Copy link

Saved my day, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: select This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

9 participants