Skip to content

[Tabs] Added tabTemplate property in Tabs component for custom tab templates. #1691

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

Merged
merged 1 commit into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/app/components/pages/components/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default class TabsPage extends React.Component {
header: 'optional',
desc: 'Override the inline-styles of the tab-labels container.',
},
{
name: 'tabTemplate',
type: 'ReactClass',
header: 'optional',
desc: 'Override the default tab template used to wrap the content of each tab element.',
},
{
name: 'value',
type: 'string or number',
Expand Down
5 changes: 4 additions & 1 deletion src/tabs/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Tabs = React.createClass({
initialSelectedIndex: React.PropTypes.number,
inkBarStyle: React.PropTypes.object,
tabItemContainerStyle: React.PropTypes.object,
tabTemplate: React.PropTypes.func,
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should have a node type here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using React.PropTypes.node, I get the following warning when I use the Tabs component:
Invalid prop 'tabTemplate' supplied to 'Tabs', expected a ReactNode.

Almost the same for React.PropTypes.element.

The reason is that we need to pass a javascript class (ReactClass) to tabTemplate prop instead of a ReactElement. Example:

import MyCustomTabTemplate from "components/MyCustomTabTemplate";

...

<Tabs tabTemplate={MyCustomTabTemplate}>
    ...
</Tabs>

Copy link
Member

Choose a reason for hiding this comment

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

Yes, my bad 👍

},

//for passing default theme context to children
Expand All @@ -36,6 +37,7 @@ const Tabs = React.createClass({
getDefaultProps() {
return {
initialSelectedIndex : 0,
tabTemplate: TabTemplate,
};
},

Expand Down Expand Up @@ -85,6 +87,7 @@ const Tabs = React.createClass({
style,
tabWidth,
tabItemContainerStyle,
tabTemplate,
...other,
} = this.props;

Expand Down Expand Up @@ -118,7 +121,7 @@ const Tabs = React.createClass({
}

tabContent.push(tab.props.children ?
React.createElement(TabTemplate, {
React.createElement(tabTemplate, {
key: index,
selected: this._getSelected(tab, index),
}, tab.props.children) : undefined);
Expand Down