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

[Hidden] Change children type to allow many and add children tests #8082

Merged
merged 9 commits into from Sep 8, 2017

Conversation

rosskevin
Copy link
Member

@rosskevin rosskevin commented Sep 7, 2017

Closes #8072

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

@rosskevin
Copy link
Member Author

codecov appears hung. It's been about 25 minutes since it should have queued there, but their status says operational. https://status.codecov.io/

});

it('should work when ChildrenArray', () => {
shallow(
Copy link
Member

Choose a reason for hiding this comment

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

We should assert the output dom.

@oliviertassinari
Copy link
Member

I feel like we are missing a part in the story. As far as I know the CSS version do not support multiple children.

@rosskevin
Copy link
Member Author

rosskevin commented Sep 7, 2017

Perhaps this would be better served by creating a <span class wrapper instead of changing this to cloning children. This would change the DOM, but it would cover all children.
@oliviertassinari

My concern is this case:

        <HiddenCss mdUp>
          <Foo />
          <Foo />
          foo
        </HiddenCss>,

Which I think would still show string foo with this implementation:

  return React.Children.map(children, child => {
    if (React.isValidElement(child)) {
      return React.cloneElement(child, {
        className: classNames(child.props.className, className.join(' ')),
      });
    }

    return child;
  });

I guess we could look for typeof child number | string and cover only those in <span class, this would leave the DOM mostly intact.

Thoughts?

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 7, 2017

Perhaps this would be better served by creating a <span class wrapper instead

We could try this approach. We would need to make sure the responsive drawers of the docs are still working. It's not guaranteed.

@rosskevin
Copy link
Member Author

@oliviertassinari it looks like the span implementation worked. I tried drawers. Also added structural tests for children just to be paranoid.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

The docs seems ok. Good job 👍

return React.cloneElement(children, {
className: classNames(children.props.className, className.join(' ')),
});
return <span className={className}>{children}</span>;
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of adding a warning if ...other is non empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll alter the current warning, since a ref is no longer valid there.

@@ -25,7 +27,11 @@ describe('<HiddenCss />', () => {
<div className="foo" />
</HiddenCss>,
);
assert.strictEqual(wrapper.props().className, `foo ${classes.onlySm}`);
assert.strictEqual(wrapper.type(), 'span');
assert.isTrue(wrapper.hasClass(classes.onlySm));
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of sticking to assert.strictEqual(X, true)? I have found two other tests file using this pattern. It's almost not used.

@rosskevin
Copy link
Member Author

I hate when this happens. All green locally, remotely, not so much.

@rosskevin
Copy link
Member Author

Wow, the simple change that I thought would never end!

@rosskevin rosskevin merged commit 68bc97b into mui:v1-beta Sep 8, 2017
@rosskevin rosskevin deleted the hidden-flow branch September 8, 2017 16:44
@oliviertassinari oliviertassinari changed the title [Hidden] change children type to allow many and add children tests [Hidden] Change children type to allow many and add children tests Sep 10, 2017
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.

None yet

2 participants