Skip to content

Setting up checkbox#3

Merged
sarahkf merged 12 commits into
masterfrom
sarahkf/checkbox
Jun 22, 2017
Merged

Setting up checkbox#3
sarahkf merged 12 commits into
masterfrom
sarahkf/checkbox

Conversation

@sarahkf
Copy link
Copy Markdown
Contributor

@sarahkf sarahkf commented Jun 15, 2017

No description provided.

Comment thread src/CheckBox.jsx Outdated
super(props);
if (props.checked === 'true') {
this.state = {
pressed: props.checked,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider only using checked in all places throughout this component -- we may not need the string value for state.pressed, and it would be good for this data to live in one place.

Comment thread src/CheckBox.jsx Outdated
const props = { ...this.props };

return (
<form>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would move this <form> containing element into the story for this component to avoid unnecessary DOM elements within the component itself.

Comment thread src/CheckBox.jsx Outdated
aria-describedby={props.describedby}
aria-checked={this.state.pressed}
tabIndex="0"
onClick={() => this.handleClick()}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be rewritten as just this.handleClick -- but you'll have to bind the context in the constructor, something like

this.handleDocumentClick = this.handleClick.bind(this);

Comment thread src/CheckBox.jsx Outdated
aria-checked={this.state.pressed}
tabIndex="0"
onClick={() => this.handleClick()}
disabled={props.disable}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would use disabled instead since that prop already exists in inputProps.

Comment thread src/CheckBox.jsx Outdated

CheckBox.propTypes = {
...inputProps,
checkLabel: PropTypes.string.isRequired,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly, you can just use label which exists within inputProps -- you don't need to add an additional custom property for the checkbox.

Comment thread src/CheckBox.jsx Outdated
});
}
if (this.props.fun) {
this.props.fun();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can just use this.props.onChange for this -- also, make sure to add a story to show this callback in action :)

@arizzitano
Copy link
Copy Markdown
Contributor

Awesome work @sarahkf. Ship it!!

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.

2 participants