Skip to content

Commit

Permalink
Fixed #618 - Render attribute for Tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Merve7 committed Nov 6, 2018
1 parent 90a874f commit 8e97e57
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/components/tabview/TabView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class TabView extends Component {
activeIndex: 0,
style: null,
className: null,
renderActiveOnly: true,
onTabChange: null
}

Expand All @@ -44,6 +45,7 @@ export class TabView extends Component {
activeIndex: PropTypes.number,
style: PropTypes.object,
className: PropTypes.string,
renderActiveOnly: PropTypes.bool,
onTabChange: PropTypes.func
};

Expand Down Expand Up @@ -116,25 +118,37 @@ export class TabView extends Component {

renderContent() {
const contents = React.Children.map(this.props.children, (tab, index) => {
const selected = this.isSelected(index);
const className = classNames(tab.props.contentClassName, 'p-tabview-panel', {'p-hidden': !selected});
const id = this.id + '_content_' + index;
const ariaLabelledBy = this.id + '_header_' + index;

return (
<div id={id} aria-labelledby={ariaLabelledBy} aria-hidden={!selected} className={className} style={tab.props.contentStyle} role="tabpanel">
{selected && tab.props.children}
</div>
);
if(this.props.renderActiveOnly) {
if(this.state.activeIndex === index) {
return this.createContent(tab,index);
}
}
else {
return this.createContent(tab,index);
}
})

return (
<div className="p-tabview-panels">
{contents}
</div>
);
}

createContent(tab, index) {
const selected = this.isSelected(index);
const className = classNames(tab.props.contentClassName, 'p-tabview-panel', {'p-hidden': !selected});
const id = this.id + '_content_' + index;
const ariaLabelledBy = this.id + '_header_' + index;

return (
<div id={id} aria-labelledby={ariaLabelledBy} aria-hidden={!selected} className={className}
style={tab.props.contentStyle} role="tabpanel">
{selected && tab.props.children}
</div>
);
}

render() {
const className = classNames('p-tabview p-component p-tabview-top', this.props.className)
const navigator = this.renderNavigator();
Expand Down

0 comments on commit 8e97e57

Please sign in to comment.