Skip to content

Commit

Permalink
add support for a id generation function
Browse files Browse the repository at this point in the history
  • Loading branch information
neeharv committed Sep 5, 2016
1 parent cb701e6 commit 6182fbb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = React.createClass({
focus: PropTypes.bool,
children: childrenPropType,
forceRenderTabPanel: PropTypes.bool,
generateIdsFn : PropTypes.func,
},

childContextTypes: {
Expand Down Expand Up @@ -169,14 +170,15 @@ module.exports = React.createClass({
const state = this.state;
const tabIds = this.tabIds = this.tabIds || [];
const panelIds = this.panelIds = this.panelIds || [];
const generateIdsFn = this.props.generateIdsFn ? this.props.generateIdsFn : uuid;
let diff = this.tabIds.length - this.getTabsCount();

// Add ids if new tabs have been added
// Don't bother removing ids, just keep them in case they are added again
// This is more efficient, and keeps the uuid counter under control
while (diff++ < 0) {
tabIds.push(uuid());
panelIds.push(uuid());
tabIds.push(generateIdsFn());
panelIds.push(generateIdsFn());
}

// Map children to dynamically setup refs
Expand Down

0 comments on commit 6182fbb

Please sign in to comment.