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

[Autocomplete][material-ui] Passing a click handler to the popup indicator #39170

Closed
2 tasks done
KarenBoyakhchyan opened this issue Sep 26, 2023 · 2 comments
Closed
2 tasks done
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow

Comments

@KarenBoyakhchyan
Copy link

KarenBoyakhchyan commented Sep 26, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:

<Autocomplete
popupIcon={
<IconButton onClick={handlePupupClick} disableRipple disableFocusRipple disableTouchRipple sx={{ py: 0 }}>
<KeyboardArrowDownIcon sx={{ color: theme.palette.primary.main }} />

}
/>

Screenshot 2023-09-26 at 16 59 37

Current behavior 😯

<Autocomplete
popupIcon={
<IconButton onClick={handlePupupClick} disableRipple disableFocusRipple disableTouchRipple sx={{ py: 0 }}>
<KeyboardArrowDownIcon sx={{ color: theme.palette.primary.main }} />

}
/>

  • If I write like this, can see the following error in the console - Failed prop type: MUI: You are providing an onClick event
    listener to a child of a button element. Prefer applying it to the IconButton directly. This guarantees that the whole will be responsive to click events.

  • If I don't put IconButton and pass onClick directly to KeyboardArrowDownIcon, I can see following error - Warning: validateDOMNesting(...): cannot appear as a descendant of .

Expected behavior 🤔

Expected:

Wrap popup icon in div.

Context 🔦

No response

Your environment 🌎

Google Chrome

@KarenBoyakhchyan KarenBoyakhchyan added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 26, 2023
@zannager zannager added component: icon button This is the name of the generic UI component, not the React module! component: autocomplete This is the name of the generic UI component, not the React module! labels Sep 26, 2023
@mj12albert
Copy link
Member

mj12albert commented Oct 3, 2023

@KarenBoyakhchyan You can pass a click handler to the popup indicator using slotProps.popupIndicator like this:

<Autocomplete
  disablePortal
  id="combo-box-demo"
  options={top100Films}
  renderInput={(params) => <TextField {...params} label="Movie" />}
  slotProps={{
    popupIndicator: {
      onClick: handleClick,
    }
  }}
/>

@mj12albert mj12albert changed the title Warning: Failed prop type: MUI: You are providing an onClick event listener to a child of a button element. Prefer applying it to the IconButton directly. This guarantees that the whole <button> will be responsive to click events. [Autocomplete][material-ui] Passing a click handler to the popup indicator Oct 3, 2023
@mj12albert mj12albert added support: question Community support but can be turned into an improvement and removed component: icon button This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 3, 2023
@mj12albert mj12albert added support: Stack Overflow Please ask the community on Stack Overflow and removed support: question Community support but can be turned into an improvement labels Nov 1, 2023
Copy link

github-actions bot commented Nov 1, 2023

👋 Thanks for using MUI Core!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://mui.com/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@github-actions github-actions bot closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

3 participants