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

Click on Checkbox Fires Twice #358

Closed
pahund opened this issue Oct 13, 2016 · 6 comments
Closed

Click on Checkbox Fires Twice #358

pahund opened this issue Oct 13, 2016 · 6 comments
Labels

Comments

@pahund
Copy link

pahund commented Oct 13, 2016

I have a checkbox with an onchange handler like this:

index_js_-private-messages-___git_private-messages

When I click the checkbox, nothing happens. I think this is because the click triggers both a click and onchange event, one ticks the checkbox, the other unchecks it again (using Redux to handle the event).

developer_tools_-eingang-pahund-private_nachrichten-motor-talk_de-http___localhost_3000

I'm using Preact 6.3.0 with Preact-Compat 3.7.1.

Is this a bug, or do I have to change my implementation when using Preact instead of React? It works without a problem with Facebook's React.

@developit
Copy link
Member

I'd need to know roughly what onChange is doing in order to diagnose. Click/change normalization is in preact-compat (here), so this issue might be better-suited to that repo.

I think you might be right though - it seems like the above linked normalization never removes the old onchange prop, so perhaps that's causing it to fire twice.

@pahund
Copy link
Author

pahund commented Oct 13, 2016

Should I move the issue to preact-compat?

In my app, when you click on a checkbox, a redux action is dispatched, which causes the state of the app to be changed, thus setting the checked prop of my Checkbox component.

@pahund
Copy link
Author

pahund commented Oct 13, 2016

Using onClick instead of onChange fixed the problem for me:
checkbox_index_js_-private-messages-___git_private-messages

@developit
Copy link
Member

developit commented Oct 13, 2016

Perfect, sounds like we just need to have preact-compat delete the onChange prop when it aliases it as onClick. Thanks for testing that out!

@pahund
Copy link
Author

pahund commented Oct 14, 2016

Glad to help, keep up the good work!

pekala pushed a commit to pekala/preact-compat that referenced this issue Dec 3, 2016
This should prevent the change event to firing twice when clicking on a
checkbox, see here: preactjs/preact#358
pekala pushed a commit to pekala/preact-compat that referenced this issue Dec 3, 2016
This should prevent the change event from firing twice when clicking on a
checkbox, see here: preactjs/preact#358
developit pushed a commit to preactjs/preact-compat that referenced this issue Dec 8, 2016
This should prevent the change event from firing twice when clicking on a
checkbox, see here: preactjs/preact#358
@developit
Copy link
Member

This has been fixed in preact-compat, and will be released shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants