-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Closed
Labels
component: chipThis is the name of the generic UI component, not the React module!This is the name of the generic UI component, not the React module!duplicateThis issue or pull request already existsThis issue or pull request already existsregression 🐛A bug, but worseA bug, but worse
Description
Steps to reproduce
- Create a Chip component
- Click on the Chip
- The application shows the following error: "Uncaught TypeError: onClick is not a function"
<Chip
label="Example Chip"
size="small"
/>
Chip.js:482 Uncaught TypeError: onClick is not a function
at Chip.Chip.useSlot (Chip.js:482:9)
at executeDispatch (react-dom-client.development.js:16501:9)
at runWithFiberInDEV (react-dom-client.development.js:844:30)
at processDispatchQueue (react-dom-client.development.js:16551:19)
at react-dom-client.development.js:17149:9
at batchedUpdates$1 (react-dom-client.development.js:3262:40)
at dispatchEventForPluginEventSystem (react-dom-client.development.js:16705:7)
at dispatchEvent (react-dom-client.development.js:20815:11)
at dispatchDiscreteEvent (react-dom-client.development.js:20783:11)
Current behavior
When clicking on a Chip without onClick handler the application shows an error.
If I set the following props:
clickable={false}
onClick={() => {}}
It stop throwing the error, but then the following is shown (not sure if related):
Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at [https://w3c.github.io/aria/#aria-hidden](vscode-file://vscode-app/c:/Users/lucas/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html).
Expected behavior
There are two expected behaviors depending on how the component should work:
- If
clickable={false}
is set or if there is noonClick
handler, theonClick
handler should be ignored, and no error should occur when clicking. - The component should warn developers when both
clickable={false}
andonClick
are provided, as these props are contradictory.
Context
The issue seems to be in the internal implementation of the Chip component where it doesn't correctly handle the combination of clickable={false}
with an onClick
handler defined. In this scenario, the component should either:
- Completely ignore the click event when
clickable={false}
is set - Warn about the contradictory props during development
This issue creates problems with accessibility as well, since it can lead to elements with aria-hidden="true"
that still receive focus, as encountered in our application.
Your environment
npx @mui/envinfo
System:
OS: Windows 11 10.0.26100
Binaries:
Node: 22.15.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.10.0 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Chrome: Not Found
Edge: Chromium (135.0.3179.85)
npmPackages:
@emotion/react: 11.14.0 => 11.14.0
@emotion/styled: 11.14.0 => 11.14.0
@mui/core-downloads-tracker: 7.1.1
@mui/lab: 7.0.0-beta.13 => 7.0.0-beta.13
@mui/material: 7.1.1 => 7.1.1
@mui/material-nextjs: ^7.1.1 => 7.1.1
@mui/private-theming: 7.1.1
@mui/styled-engine: 7.1.1
@mui/system: 7.1.1 => 7.1.1
@mui/types: 7.4.3
@mui/utils: 7.1.1 => 7.1.1
@mui/x-date-pickers: 8.5.0 => 8.5.0
@mui/x-internals: 8.5.0
@types/react: 19.1.6 => 19.1.6
react: 19.1.0 => 19.1.0
react-dom: 19.1.0 => 19.1.0
typescript: 5.8.3 => 5.8.3
Google Chrome
Search keywords: Chip clickable onClick TypeError Material-UI MUI
nekoya
Metadata
Metadata
Assignees
Labels
component: chipThis is the name of the generic UI component, not the React module!This is the name of the generic UI component, not the React module!duplicateThis issue or pull request already existsThis issue or pull request already existsregression 🐛A bug, but worseA bug, but worse