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 updates from responsify checkbox #73

Merged
merged 9 commits into from
Feb 15, 2017
Merged

Conversation

unjust
Copy link
Contributor

@unjust unjust commented Feb 9, 2017

Related issues

Fixes https://meetup.atlassian.net/browse/MUP-7777

Description

Checkbox component for Event create. I pulled the initial files out of responsify and made some changes. Tests to come.

Screenshots (if applicable)

screen shot 2017-02-09 at 12 03 20 pm


screen shot 2017-02-09 at 2 54 42 pm

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.8%) to 79.927% when pulling 8a98ef5 on MUP-7777_checkbox into fc65369 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.4%) to 80.292% when pulling c79705f on MUP-7777_checkbox into fc65369 on master.

{...other}>
<FlexItem shrink>
<input type='checkbox'
name={name}
Copy link
Contributor

Choose a reason for hiding this comment

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

My information may be out of date, but a good practice used to be making name and id attributes have the same value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the case of a set of checkboxes, they all have the same name in a set - so a unique id can't be just the name.
the checkbox can just compose an id out of a name and value and omit the id prop, if thats better than allowing it to pass in an id.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.7%) to 85.409% when pulling 0ad68ec on MUP-7777_checkbox into fc65369 on master.

src/Checkbox.jsx Outdated

Checkbox.propTypes = {
checked: React.PropTypes.bool,
label: React.PropTypes.string,

Choose a reason for hiding this comment

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

We would ideally make this a shape which can take an element along with string so it can handle translations. For reference you can see https://github.com/meetup/meetup-web-components/blob/master/src/PageHead.jsx#L76

Copy link
Contributor

Choose a reason for hiding this comment

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

there is technically a way to get a raw translated string, but I agree that it would be nice to just pass in a <FormattedMessage> element.


it('should be checked when specified', function() {
checkbox = TestUtils.renderIntoDocument(<Checkbox name='greeting' id='hello' value='hello' checked />);
checkboxNode = ReactDOM.findDOMNode(checkbox);
Copy link

@eilinora eilinora Feb 13, 2017

Choose a reason for hiding this comment

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

We have been having discussions on using findDOMNode in some PR's so not gonna mark this as a change request but... offering this as an alternative approach to writing these tests. You can also read more about this here

it("renders a list in a box with proper CSS classes", function() {
    let box = this.TestUtils.findRenderedDOMComponentWithTag(this.component, "div");
    expect(box.props.className).toEqual("invitation-list-container");

    let list = this.TestUtils.findRenderedDOMComponentWithTag(box, "ul");
    expect(list.props.className).toEqual("invitation-list");
  });

storiesOf('Checkbox', module)
.add('default', () => <Checkbox id='nada' name='no-name' checked={false} />)
.add('with label', () => <Checkbox label='Ketchup' id='ketchup' checked={false} name='condiment' />)
.add('checked', () => <Checkbox label='Mustard' checked id='mustard' name='condiment' />);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so from what I understand, if this is a controlled component, value or in this case checked always has to be passed in. if I don't I get the controlled vs uncontrolled warning. If there is another way that if checked doesn't have to be specified as a prop if false, let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also TODO: make a list of checkboxes to demo in storybook.

{...other}>
<FlexItem shrink>
<input type='checkbox'
name={name}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the case of a set of checkboxes, they all have the same name in a set - so a unique id can't be just the name.
the checkbox can just compose an id out of a name and value and omit the id prop, if thats better than allowing it to pass in an id.

src/Checkbox.jsx Outdated
/>
</FlexItem>
<FlexItem>
<label className='label--minor' htmlFor={elId}>{label}</label>
Copy link
Contributor

Choose a reason for hiding this comment

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

TL;DR: Checkbox labels shouldn't be bold

The label--minor class was something we were playing with to "un-bold" <label> for radio and checkbox inputs. We wanted to use the bold text for <legend> when we have a set of checkboxes that need to be labeled.
E.g.: ```


Colors

Red

Blue

```

The CSS behind label--minor didn't make it into this repo, it should probably go in swarm-sasstools

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. what class do we prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Go ahead and use label--minor in this component; I'll make sure the class will make it into swarm-sasstools with this PR: #80

This has been filed in Jira as: https://meetup.atlassian.net/browse/SDS-157

Once swarm-sasstools is merged into this repo, the class will be defined and your labels will get prettier.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 85.461% when pulling bac2459 on MUP-7777_checkbox into bbb5964 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 85.461% when pulling 44425b5 on MUP-7777_checkbox into bbb5964 on master.


it('exists', function() {
expect(checkbox).not.toBeNull();
});

Choose a reason for hiding this comment

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

because your using findRenderedDOMComponent this wont return null when it fails, instead it throws an error. i would do

expect(() => TestUtils.findRenderedDOMComponentWithType(checkboxComponent, Checkbox)).not.toThrow() 

instead

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 85.461% when pulling 8bf4588 on MUP-7777_checkbox into bbb5964 on master.

@unjust unjust merged commit 96cfc21 into master Feb 15, 2017
@chenrui333 chenrui333 deleted the MUP-7777_checkbox branch September 16, 2019 21:52
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.

6 participants