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

fix(Checkbox): match DOM checkbox behavior #2748

Merged
merged 17 commits into from
Dec 9, 2018
Merged

Conversation

levithomason
Copy link
Member

@levithomason levithomason commented Apr 28, 2018

Fixes #2587

A controlled Checkbox did not fire onClick / onChange when pressing spacebar after focus. This was strictly when a functional state updater was used.

Changes

I've commented on relevant changes to help separate the prettier updates from the actual code changes.

  1. Change Checkbox handlers so that mouse down, mouse up, click, and change events are identical to the DOM checkbox
  2. Add example comparing a vanilla DOM checkbox to our Checkbox with an event log
  3. Rearrange "Remote" checkbox example from "States" to "Usage" and rename "Controlled"

TODO

Help much appreciated! Make PRs against fix/checkbox-spacebar instead of master.

  • Add/fix tests (Note, the new example works but the tests don't seem to think so.)

>
<input
{...htmlInputProps}
checked={checked}
className='hidden'
id={id}
name={name}
onClick={this.handleInputClick}
onChange={this.handleInputClick}
Copy link
Member Author

@levithomason levithomason Apr 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant change, remove duplicate click firing.

onChange={this.handleContainerClick}
onMouseDown={this.handleMouseDown}
onMouseUp={this.handleMouseUp}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant change

_.invoke(this.props, 'onMouseUp', e, { ...this.props, checked: !!checked, indeterminate: !!indeterminate })

this.handleClick(e)
}
Copy link
Member Author

@levithomason levithomason Apr 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant change, click is fired on mouse up.

* @param {object} data - All props and current checked/indeterminate state.
*/
onMouseUp?: (event: React.MouseEvent<HTMLInputElement>, data: CheckboxProps) => void;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant change

@layershifter
Copy link
Member

I've checked this branch, Checkbox doesn't work at all, at example's log I have:

15:25:52: MouseUp       { checked: false } // click again
15:25:52: MouseDown     { checked: false }
15:25:51: MouseUp       { checked: false } // first click
15:25:51: MouseDown     { checked: false }

Oleksandr Fediashov added 10 commits July 13, 2018 14:36
…React into fix/checkbox-spacebar

Signed-off-by: Oleksandr Fediashov <[email protected]>

# Conflicts:
#	docs/app/Examples/modules/Checkbox/States/CheckboxExampleRemoteControl.js
#	docs/app/Examples/modules/Checkbox/States/index.js
#	docs/app/Examples/modules/Checkbox/Usage/CheckboxExampleRemoteControl.js
#	docs/src/examples/modules/Checkbox/States/CheckboxExampleRemoteControl.js
#	src/modules/Checkbox/Checkbox.d.ts
#	src/modules/Checkbox/Checkbox.js
Signed-off-by: Oleksandr Fediashov <[email protected]>
Signed-off-by: Oleksandr Fediashov <[email protected]>
Signed-off-by: Oleksandr Fediashov <[email protected]>
Signed-off-by: Oleksandr Fediashov <[email protected]>
Signed-off-by: Oleksandr Fediashov <[email protected]>
@layershifter
Copy link
Member

@levithomason I've fixed tests and replaced some of them with new, also updated example.

There is a single failing conformance test. I think that we can disable it all, what you think?

@codecov-io
Copy link

codecov-io commented Dec 9, 2018

Codecov Report

Merging #2748 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2748      +/-   ##
==========================================
+ Coverage   99.89%   99.89%   +<.01%     
==========================================
  Files         170      170              
  Lines        2801     2806       +5     
==========================================
+ Hits         2798     2803       +5     
  Misses          3        3
Impacted Files Coverage Δ
src/modules/Checkbox/Checkbox.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 132e73f...2121dbd. Read the comment docs.

@levithomason
Copy link
Member Author

I've fixed the last broken test. The Checkbox now has full parity with the HTML checkbox. See the new example for confirmation: http://localhost:3000/modules/checkbox/#usage-dom-comparison

The onChange, onClick, onMouseDown, and onMouseUp events are fired in the same order and with the same arguments as a vanilla HTML checkbox.

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

Successfully merging this pull request may close these issues.

Checkbox: doesn't toggle its state, when using only the keyboard
3 participants