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

Huge problem with onClick event on Buttons with chrome #7974

Closed
llllGEM opened this issue Aug 31, 2017 · 8 comments
Closed

Huge problem with onClick event on Buttons with chrome #7974

llllGEM opened this issue Aug 31, 2017 · 8 comments
Labels
support: question Community support but can be turned into an improvement

Comments

@llllGEM
Copy link

llllGEM commented Aug 31, 2017

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
@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 31, 2017

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.

@llllGEM
Copy link
Author

llllGEM commented Aug 31, 2017

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

@oliviertassinari
Copy link
Member

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

@slavab89
Copy link
Contributor

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

@llllGEM
Copy link
Author

llllGEM commented Sep 13, 2017

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

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

@slavab89
Copy link
Contributor

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?

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 13, 2017

@llllGEM Use event.currentTarget over event.target.

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement v1 labels Sep 13, 2017
@AndreyK-git
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

4 participants