The list of properties on the doc doesn't include onClick
(http://www.material-ui.com/#/components/icon-button)
How do I know I need to use onClick for click handler?
The React onClick event handler enables you to call a function and trigger an action when a user clicks an element, such as a button, in your app. Event names are written in camelCase, so the onclick event is written as onClick in a React app. In addition, React event handlers appear inside curly braces.
To set your mind at ease, the onClick event does work with divs in react, so double-check your code syntax.
Adding EventsReact events are written in camelCase syntax: onClick instead of onclick . React event handlers are written inside curly braces: onClick={shoot} instead of onClick="shoot()" .
The Material-UI documentation does not list the standard React (native browser) events:
https://facebook.github.io/react/docs/events.html#mouse-events
This is because it's expected that you are already aware of the available native events. For example, you can also use onWheel
. It would be a long and redundant list if all the native events were included.
As kouak explains, other props (such as onClick
) are passed down to a relevant child component.
Random example:
<Button color="primary" onClick={() => { console.log('onClick'); }}> Primary </Button>
You can add an wrapper over the <IconButton/>
to get the onClick
event.
Example
render() { return <div class="font-icon-wrapper" onClick={this.fontIconClick}> <IconButton iconClassName="muidocs-icon-custom-github" /> </div> }
This should definitely work...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With