question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[IconButton] Improve onClick warning

See original GitHub issue

Not sure where to put this, but I’m getting the warning:

Failed prop type: Material-UI: You are providing an onClick event listener to a child of a button element.
Firefox will never trigger the event.
You should move the onClick listener to the parent button element.
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Warning thrown

Expected Behavior 🤔

Warning is a non-issue (in Firefox, from what I gather, in this situation), so this warning shouldn’t be there.

I get why this is being thrown, the expand icon is wrapped in a button base (IconButton), but I feel like the warning is misleading.

Also, curious to know if you guys had a conversation about ever giving users the ability to pass a function to the IconButton component? If not, I wouldn’t mind making a PR. Not sure how it would look like yet, but what would be wrong with something like,

type TAccordion = {
       . . . . .
       onExpandIconClick: (...params: any[]) => any;
}

const AccordionSummary = React.forwardRef(function AccordionSummary(props, ref) {
   const {
        onExpandIconClick,
        classes,
        expandIcon,
        IconButtonProps = {},
        ...other
   } = props;
   . . . . .
   return {
   . . . . .
    {expandIcon && (
        <IconButton
            onClick={onExpandIconClick}
            edge='end'
            component='div'
            tabIndex={null}
            role={null}
            aria-hidden
            {...IconButtonProps}
            className={clsx(
                classes.expandIcon,
                {
                    [classes.expanded]: expanded,
                },
                IconButtonProps.className,
            )}
        >
            {expandIcon}
        </IconButton>
    )}

Steps to Reproduce 🕹

Edit affectionate-thunder-uqyvn

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
crorafcommented, Sep 29, 2020

I will make this PR tomorrow (if I dont forget) so the others can also comment if it makes sense. @mkhoussid the conclusion for you is as per said before. You shouldn’t use expandIcon for this, but do it by appropriately laying out the children of AccordionSummary.

0reactions
crorafcommented, Sep 30, 2020

@pranjanpr yes.

Also there is an unrelated second issue that I’m doing a PR for (you can see the PR link slightly above), which is slightly more advanced.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[IconButton] Improve onClick warning · Issue #22804 - GitHub
Not sure where to put this, but I'm getting the warning: Failed prop type: Material-UI: You are providing an onClick event listener to...
Read more >
react Material-ui, How do I know I can use onClick for button?
Props that are not cited in the doc are passed down into their internal <EnhancedButton /> component which will handle onClick just fine....
Read more >
Button icon with possibility of passing parameters and get ...
I have a IconButton , but to pass parameters to the JS, I use regular Icon with span like this : <span onclick="{!c....
Read more >
IconButton API - Material UI - MUI
API reference docs for the React IconButton component. ... MuiIconButton-colorWarning, Styles applied to the root element if color="warning" .
Read more >
Icon Button API - React Magma
The onClick event will fire when the button is clicked, or when the enter or spacebar key is pressed. Events do not fire...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found