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

feat(checkbox): Add new component #296

Merged
merged 22 commits into from
Oct 2, 2018
Merged

feat(checkbox): Add new component #296

merged 22 commits into from
Oct 2, 2018

Conversation

bonniezhou
Copy link
Contributor

Fixes #156

@codecov-io
Copy link

codecov-io commented Sep 27, 2018

Codecov Report

Merging #296 into master will decrease coverage by 0.39%.
The diff coverage is 89.06%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #296     +/-   ##
=========================================
- Coverage   97.47%   97.08%   -0.4%     
=========================================
  Files          33       35      +2     
  Lines        1306     1370     +64     
  Branches      127      132      +5     
=========================================
+ Hits         1273     1330     +57     
- Misses         33       40      +7
Impacted Files Coverage Δ
packages/checkbox/NativeControl.js 100% <100%> (ø)
packages/checkbox/index.js 88.13% <88.13%> (ø)

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 fe14736...14d0e9e. Read the comment docs.

this.setState({classList});
},
hasNativeControl: () => true,
isAttachedToDOM: () => true,
Copy link

Choose a reason for hiding this comment

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

I see in the core component, it just checks for a parentNode. I'm wondering when this would not be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #3691

Copy link

Choose a reason for hiding this comment

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

Can you add a react issue too, linking to #3691

id={nativeControlId}
checked={this.state.checked}
disabled={disabled}
aria-checked={this.state['aria-checked']}
Copy link

Choose a reason for hiding this comment

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

add aria-checked to the initial state.

@@ -0,0 +1,28 @@
{
"name": "@material/react-checkbox",
"version": "0.5.0",
Copy link

Choose a reason for hiding this comment

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

0.0.0

},
"dependencies": {
"@material/react-ripple": "^0.5.0",
"@material/ripple": "^0.40.0",
Copy link

Choose a reason for hiding this comment

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

I think you can remove @material/ripple

import React from 'react';
import './index.scss';

import Checkbox from '../../../packages/checkbox';
Copy link

Choose a reason for hiding this comment

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

packages/checkbox/index

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the benefit of this? I see that some screenshot tests import /index and some don't

Copy link

Choose a reason for hiding this comment

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

we should be using /index. it doesn't use the built version in /dist. Its easier to debug and fix issues since we can just update the /index.js file. We also know what were testing against every time (not /dist/index).

assert.isFalse(wrapper.state().classList.has('test-class-name'));
});

test('#adapter.isChecked returns state.checked', () => {
Copy link

Choose a reason for hiding this comment

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

can you add a test for the positive version of this test as well as the indeterminate test below

test('#adapter.removeNativeControlAttr sets aria-checked state as false', () => {
const wrapper = shallow(<Checkbox />);
wrapper.instance().foundation_.adapter_.removeNativeControlAttr('aria-checked');
assert.isFalse(wrapper.state()['aria-checked']);
Copy link

Choose a reason for hiding this comment

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

I think this is false even without line 106. Add this line above:

wrapper.setState({'aria-checked': true})

});

test('passes nativeControlId to NativeControl through props', () => {
const wrapper = shallow(<Checkbox nativeControlId={'test-id'}/>);
Copy link

Choose a reason for hiding this comment

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

no need to interpolate a string:

 nativeControlId='test-id'

},
};
wrapper.instance().foundation_.handleChange = td.func();
nativeControl.props().onChange(mockEvt);
Copy link

Choose a reason for hiding this comment

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

instead of directly calling onChange, use enzyme's simulate method

nativeControl.simulate('change', mockEvt);```

indeterminate: false,
},
};
nativeControl.props().onChange(mockEvt);
Copy link

Choose a reason for hiding this comment

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

same here

disabled,
} = this.props;

if (checked !== prevProps.checked) {
Copy link

Choose a reason for hiding this comment

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

this and the below can be put together in one setState call. In order to update indeterminate or checked, you will need to set both, so putting it together in one call is fine.

 if (checked !== prevProps.checked || indeterminate !== prevProps.indeterminate) {
  this.setState({indeterminate, checked})
... 

Then put the setState call into a function, since its shared logic from the onChange method

@moog16 moog16 added this to the 0.6.0 milestone Sep 28, 2018
@moog16
Copy link

moog16 commented Sep 28, 2018

Also I noticed you're not implementing the forceLayout or the getNativeControl. I realize that getNativeControl is mainly for the objectPropertyDescriptors. Are we going to move it out of the foundation into the component in Web?

@bonniezhou
Copy link
Contributor Author

getNativeControl should be removed in #2684.
Let me double check if forceLayout/isAttachedToDOM is necessary in MDC Web

@bonniezhou
Copy link
Contributor Author

Filed #3691 for isAttachedToDOM and #3692 for forceLayout.

<input
type='checkbox'
className='mdc-checkbox__native-control'
ref={rippleActivatorRef}
Copy link

Choose a reason for hiding this comment

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

I think we should be doing inputRefs...so if someone passes in a prop, they should be able to programmatically focus a checkbox.focus(). This can be a separate task, especially since we have so many of these NativeX elements. LMK what you think.

Copy link

@moog16 moog16 left a comment

Choose a reason for hiding this comment

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

  • update screenshot test golden file
  • one comment about merging logic for 1 function

then looks good to me!

aria-checked={this.state['aria-checked']}
onChange={(evt) => {
const {checked, indeterminate} = evt.target;
this.setState({checked, indeterminate}, () => {
Copy link

Choose a reason for hiding this comment

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

this and line 64 can be a separate function since its the same logic

@bonniezhou bonniezhou merged commit fbe7999 into master Oct 2, 2018
@bonniezhou bonniezhou deleted the feat/checkbox branch October 2, 2018 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants