Material-ui: Huge problem with onClick event on Buttons with chrome

Created on 31 Aug 2017  路  8Comments  路  Source: mui-org/material-ui

Problem description

Every event with onClick prop on every Button type (Raisedbutton or Flatbutton or Icon etc...)
I can't get the event.target.id or any other prop from the target as it is undefined, works perfectly on firefox but not on chrome, can you provide a workaround or a fix ?


toggleUpdate(event){ event.target.id //undefined}

Versions

  • Material-UI: 0.19
  • React: "^15.6.1"
  • Browser: Chrome
question

Most helpful comment

@llllGEM Use event.currentTarget over event.target.

All 8 comments

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. While we haven't tested it, I think that the issue is most likely fixed on that branch. Hence, I'm closing it.
Still, we will accept PR fixes until v1-beta takes over the master branch.

You made too many changes and plus there are less components in the beta, could you provide a workaround please to use chrome ? @oliviertassinari

ps: your project is awesome, but I juste need one thing, the event.target.id with chrome on a button, the rest works perfectly

@llllGEM Feel free to submit a PR to address the issue, we will review it. We are now focusing on the v1-beta branch.

This works on V1. Just verify that you do gave a id on the button element that's rendered.

@slavab89 no it doesn't, here is my button

when I click on the label inside the button I don't get the Id I must click inside the button outside the label for the handleclick method to get the id, which is very unpleasant and not a stable behavior, try it yourself on chrome, BTW I updated to beta9 and the issue is still there

I see what you mean
Here is a reproduction: https://codesandbox.io/s/w0nq43yw67

So based on the spec + stackoverflow it seems that button cant contain anything that's considered clickable and the recommendation is to use div instead when you want to have a styled button.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
Reference: https://stackoverflow.com/questions/11069410/click-event-for-element-nested-within-a-button

As an reference, material-web-components did a simple string inside the button while applying the ripple in some other manner
https://material-components-web.appspot.com/button.html
@oliviertassinari any knowledge on this?

@llllGEM Use event.currentTarget over event.target.

@oliviertassinari thank you sir! I was having the same problem and that did the trick

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pola88 picture pola88  路  3Comments

ericraffin picture ericraffin  路  3Comments

revskill10 picture revskill10  路  3Comments

ghost picture ghost  路  3Comments

activatedgeek picture activatedgeek  路  3Comments