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

Checkbox: onClick doesn't fire when inside a Dropdown #2121

Open
mihai-dinculescu opened this issue Sep 25, 2017 · 12 comments
Open

Checkbox: onClick doesn't fire when inside a Dropdown #2121

mihai-dinculescu opened this issue Sep 25, 2017 · 12 comments

Comments

@mihai-dinculescu
Copy link
Member

mihai-dinculescu commented Sep 25, 2017

Steps

Add a checkbox inside a dropdown, either as header or item.

Expected Result

  • onClick fires

Actual Result

  • onClick doesn't fire
  • also note the weird font

Version

0.74.1

Testcase

https://codepen.io/anon/pen/zENBPx

@levithomason
Copy link
Member

Looks like the Dropdown is overriding onClick when looping over the options and creating DropdownItems. Seen here.

Workaround

Use onMouseDown instead. Working fork https://codepen.io/levithomason/pen/qPRqRg.

Fix

The DropdownItem.create() factory call needs to no override the onClick handler, but wrap it. An example of this is shown in the same file, Dropdown.js, where handleIconOverrides() is used to wrap the icon handlers and not override them.

@levithomason
Copy link
Member

Note, children are not supported in a Dropdown. Use the options prop instead. The children API will be removed.

@mihai-dinculescu
Copy link
Member Author

I'll have a go at getting it fixed.

@mihai-dinculescu
Copy link
Member Author

mihai-dinculescu commented Sep 26, 2017

@levithomason I don't think that DropdownItem is the issue. The Checkbox is displayed inside a DropdownHeader after all, not inside an Item. handleItemClick is not called.

Adding multiple={true} fixes the problem, but it's something I'd prefer not to do.

@stale
Copy link

stale bot commented Feb 4, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 4, 2018
@ghost
Copy link

ghost commented Feb 22, 2018

don't close this issue bot

@stale stale bot removed the stale label Feb 22, 2018
@tarang9211
Copy link
Contributor

@levithomason or anyone here, what's the update on this issue? any ideas on how to fix?

@nwpray
Copy link

nwpray commented Apr 13, 2018

I noticed that when you click on other Items or Headers, the order of called Dropdown methods are:

image

But when you click on the checkbox its order is:

image

So it appears that the blur event is being called before the mouseDown event which causes the close method of Dropdown to be called without the isMouseDown property being set in the handleMouseDown method. I tried with vanilla html and the order is mouseDown->blur so I am a bit confused. I will keep looking into this.

@walter76
Copy link

walter76 commented May 17, 2018

Hi,

I gave this issue a shot and implemented what was suggested by @levithomason in a previous comment. But this did not work as the onClick handler will never be called. I checked this by adding a debug() output into onClick.

As it was also suggested to not use children, but instead use the options property, I changed the example to do so. But this also did not change anything. The onClick handler on the DropdownItem is simply not called. My guess is, that handleMouseDown() captures the event so it is not being further propagated.

I could hook into handleMouseDown() and propagate onClick, but this kind of feels like a hack. Are there any other ideas?

@ghost
Copy link

ghost commented Jul 30, 2018

I tried to replicate the workaround @levithomason shared and it worked for me.

Sandbox

@Shenrak
Copy link

Shenrak commented Aug 23, 2018

I would like to trigger a simple onClick :

public onClick = () => this.setState({loading: true})

That would display the loading prop of the dropdown object onOpen, but it doesn't seem to work.
onOpen, onMouseDown, onFocus don't work either...

Edit : onOpen is perfectly working, i was too dumb to check my shouldComponentUpdate. Sorry.

@levithomason
Copy link
Member

Note, I've given a workaround and a proper fix here #2121 (comment). I've also included a reference to the proper pattern in another component that can be copied. Any PR implementing this would be much appreciated!

@Semantic-Org Semantic-Org locked as resolved and limited conversation to collaborators Dec 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants