Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to keep option list open when option's button clicked in MUI v5 Autocomplete?

How can I add a play button to every option in MUI v5 Autocomplete component so that when clicked on that button no option selected and option list was not closed?

Here’s codesandbox:
https://codesandbox.io/s/silly-monad-6z3144?file=/src/Autocomplete.tsx

  <Autocomplete
    disableCloseOnSelect={disableCloseOnSelect}
    options={options}
    getOptionLabel={(option: any) => option[optionLabel]}
    isOptionEqualToValue={(option: any, value: any) => option.id === value.id}
    renderInput={(params) => {
      return <TextField {...params} placeholder={placeholder} />;
    }}
    PaperComponent={AutocompletePaper}
    renderOption={(renderProps, option: any, { selected, inputValue }) => {
      return (
        <span {...renderProps}>
          <Stack>
            <PlayArrowRoundedIcon onClick={() => console.log('clicked')} />

            <StyledAvatar src={option.avatar} />
            <span>
              {option.name}
            </span>
          </Stack>
        </span>
      );
    }}
  />

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

use stopPropagation for it:

<PlayArrowRoundedIcon
   onClick={(e) => { 
     e.stopPropagation()
     console.log("click on play button")
   }}
/>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading