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: Initial implementation of Tabs component #131

Merged
merged 7 commits into from
Sep 11, 2016

Conversation

ajainarayanan
Copy link
Contributor

@ajainarayanan ajainarayanan commented Sep 8, 2016

PR for #72

Note:
  • Not sure if I adhered to coding style. Please let me know if I missed something
  • Will squash all the commits if the changes are ok
  • Have added some comments, places where I thought needed some explanation. Please feel free to remove them if you think its not right.
  • If someone can point me how to update the test coverage would make sure it is 100%

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 99.541% when pulling 4a4893b on ajainarayanan:feature/Tabs into af874bc on reactstrap:master.

@eddywashere
Copy link
Member

Couple of comments

I think this could use the .tab-content, .tab-pane classes and .active from http://v4-alpha.getbootstrap.com/components/navs/#using-data-attributes (fade option could be part of a different pr). I should have mentioned that in GitHub issue.

Also, instead of iterating through children and setting state, you could use context to simplify the TabContent component https://facebook.github.io/react/docs/context.html.

Ex: add getChildContext to TabContent, return {activeTab: this.props.activeTab}. In TabPane, it can accept a 2nd argument, context, from there you can compare props.tabId to context.activeTab and add the .active class if they are equal.

For coverage, there's a folder in test directory called coverage and somewhere inside is a root index.html. I usually open that in a browser and sort by missing coverage

Thanks for tackling this! feel free to ping me here or in slack if you need anything. The link to it is in contributing.md

@ajainarayanan
Copy link
Contributor Author

@eddywashere Will work on this weekend. Just one minor question, react docs mentions using context only when it is absolutely necessary and try to avoid it as much as possible. Is there any specific reason why we should use contextTypes for communicating with children? The props seemed to be simple. Is there any specific reason we should use contextTypes? (Sorry if my question is a little silly, I am relatively new to react :))

@eddywashere
Copy link
Member

Glad you brought that up. "Using context makes your components more coupled" I interpret that as a positive effect in this case. TabPanes are coupled to TabContent. It's partially to save time passing the same prop to child components. If the API changes we could always switch to cloning children(TabPanes) with the activeTab prop from TabContent. That wouldn't cause a breaking change and seems like an easy win for keeping things simple.

@ajainarayanan
Copy link
Contributor Author

@eddywashere That was super useful! Have updated the PR. Please review and let me know I have missed anything.

};
}
componentWillReceiveProps(nextProps) {
this.setState({
Copy link
Member

Choose a reason for hiding this comment

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

you should check if nextProps.activeTab !== this.props.activeTab before using setState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why github is not collapsing or updating this comment but this is fixed

@eddywashere
Copy link
Member

thanks a ton for working through this @ajainarayanan! I'll squash and merge via github.

@eddywashere eddywashere merged commit 2957ede into reactstrap:master Sep 11, 2016
it('should show no active tabs if active tab id is unknown', () => {
let tab1 = mount(<TabsExample />);
const instance = tab1.instance();
expect(instance instanceof TabsExample).toBe(true);
Copy link
Member

@TheSharpieOne TheSharpieOne Sep 13, 2016

Choose a reason for hiding this comment

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

are you testing the example?.... as in your are not testing the actual Tab component.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TabExample is a wrapper around the Tab. The aim in this test is to have a click initiated from the wrapper that toggles the TabContent (in this case an invalid case). The clicking and managing ActiveTab is not in the scope of the Tab component. The test still focuses on testing the Tab and not the TabsExample though.

Copy link
Member

Choose a reason for hiding this comment

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

It's just this except tests the example directly, seems pointless.

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

4 participants