From 5587cef8c54b5297c3a0e8805bd0907aa731a55b Mon Sep 17 00:00:00 2001 From: Mustafa Skir Date: Fri, 21 Dec 2018 00:05:39 +0300 Subject: [PATCH 1/3] Update default Tab index I have many routes [likes, search, home, profile, settings] and suggest making the default route to be in the middle, or we can add defaultTab prop into tabs property which should be the default regards --- lib/TabList.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/TabList.js b/lib/TabList.js index f383483..91315b7 100644 --- a/lib/TabList.js +++ b/lib/TabList.js @@ -42,7 +42,8 @@ export default class TabList extends React.PureComponent { constructor(props) { super(props) - + // Default tab index is in the middle + let defaultTabIndex = Math.floor(props.tabs.length / 2) // When the user presses a Tab, the Decorator data is stored in here and // retrieved when the Tab visually becomes active. // We need to temporarily store it for the controlled component because we @@ -53,7 +54,7 @@ export default class TabList extends React.PureComponent { this.isControlled = props.activeTab != null this.state = { - activeTab: this.isControlled ? props.activeTab : props.tabs[0].key + activeTab: this.isControlled ? props.activeTab : props.tabs[defaultTabIndex].key } } From de2eac74d199e85391911e9d2f38dca693c17572 Mon Sep 17 00:00:00 2001 From: Mustafa Skir Date: Fri, 21 Dec 2018 00:53:57 +0300 Subject: [PATCH 2/3] Added defaultTabIndex property, Added defaultTabIndex property, if exist respectively will be the default tab, otherwise, the default is the first index of tabsdefaultTabIndex should pass as a prop to , like so regards --- lib/TabList.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/TabList.js b/lib/TabList.js index 91315b7..8d76c3c 100644 --- a/lib/TabList.js +++ b/lib/TabList.js @@ -42,8 +42,8 @@ export default class TabList extends React.PureComponent { constructor(props) { super(props) - // Default tab index is in the middle - let defaultTabIndex = Math.floor(props.tabs.length / 2) + // expect defaultTabIndex otherwise default should be first index + let defaultTabIndex = props.defaultTabIndex || 0 // When the user presses a Tab, the Decorator data is stored in here and // retrieved when the Tab visually becomes active. // We need to temporarily store it for the controlled component because we From 947fc6ebc432b3bda0c5d621ca5adc8e8f4c1d7b Mon Sep 17 00:00:00 2001 From: Mustafa Skir Date: Fri, 21 Dec 2018 01:01:39 +0300 Subject: [PATCH 3/3] Update TabList.js --- lib/TabList.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/TabList.js b/lib/TabList.js index 8d76c3c..86fe1a2 100644 --- a/lib/TabList.js +++ b/lib/TabList.js @@ -42,8 +42,6 @@ export default class TabList extends React.PureComponent { constructor(props) { super(props) - // expect defaultTabIndex otherwise default should be first index - let defaultTabIndex = props.defaultTabIndex || 0 // When the user presses a Tab, the Decorator data is stored in here and // retrieved when the Tab visually becomes active. // We need to temporarily store it for the controlled component because we @@ -54,7 +52,7 @@ export default class TabList extends React.PureComponent { this.isControlled = props.activeTab != null this.state = { - activeTab: this.isControlled ? props.activeTab : props.tabs[defaultTabIndex].key + activeTab: this.isControlled ? props.activeTab : props.tabs[props.defaultTabIndex || 0].key } }