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

Child elements inside the <Button /> should be click-through #7034

Closed
mim-Armand opened this issue Jul 31, 2017 · 5 comments
Closed

Child elements inside the <Button /> should be click-through #7034

mim-Armand opened this issue Jul 31, 2017 · 5 comments
Labels
help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request.

Comments

@mim-Armand
Copy link

mim-Armand commented Jul 31, 2017

Version

2.12.3

Environment

MAC, Chrome 61,

Reproduction link

https://codepen.io/anon/pen/EvKmNO?editors=001

Steps to reproduce

Please looks at the console to inspect the behavior in the Codepen sample while clicking on the <button/>, the <i/> and the <span/> elements

What is expected?

The target property of the emitted event should always be the <button />

What is actually happening?

The event is triggered with the target set to other elements ( child elements )
Clicking on the text and / or icon in the button changes the target property of the event to the <span /> or <i /> elements instead of element


adding the rule pointer-events: none to the children solves the problem but that's just a suggestion as I wasn't sure if this is actually a bug or a feature..

@ddcat1115
Copy link
Contributor

I think it's a bug... Could you give us a PR to fix it?

@mim-Armand
Copy link
Author

Sure, I will try to make a PR this week 👍

@ddcat1115 ddcat1115 added the help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request. label Aug 3, 2017
@jddxf
Copy link

jddxf commented Apr 26, 2018

@benjycui I don't quite understand why the event target should always be set to the button element. The target of an event should be the element where the event originates.

@mim-Armand
Copy link
Author

mim-Armand commented Apr 27, 2018

@jddxf exactly, when you click on a <Button/> you expect it to be passed as the target, regardless on which part of the <Button/> you click on. ( that's teh whole promise of modules and components, a set of inputs and a set of consistent out-puts )
Now the Button component may have a <span/> or another element under the hood ( Which is not even usable as nobody knows it's there, it's litterally just under the hood ), these elements may be wrappers, may be invisible or integrated in the <Button/>. now imagine clicking on the same Button behaves differently each time, only because some times you clicked on the invisible span inside the Button and some times on the Button itself, that for sure is not consistent or desired.
So to your point, imo the event target should always be set to the button, when the Button element was clicked ( sub-components and elements should be click-through )

@jddxf
Copy link

jddxf commented Apr 27, 2018

@mim-Armand Got your point. IMO, it may be better to provide a Button instance as an argument in the callback if you'd like to offer component-level consistency. If the argument is an Event(or more specifically React.SyntheticEvent) instance, I suppose its target being the real event target, which offers dom-level consistency.
As a side note, you can always refer to the button with event.currentTarget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted The suggestion or request has been accepted, we need you to help us by sending a pull request.
Projects
None yet
Development

No branches or pull requests

3 participants