|
@@ -77,7 +77,7 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
|
|
this.foundation = new TabsFoundation(this.adapter);
|
|
this.foundation = new TabsFoundation(this.adapter);
|
|
this.state = {
|
|
this.state = {
|
|
activeKey: this.foundation.getDefaultActiveKey(),
|
|
activeKey: this.foundation.getDefaultActiveKey(),
|
|
- panes: [],
|
|
|
|
|
|
+ panes: this.getPanes(),
|
|
prevActiveKey: null,
|
|
prevActiveKey: null,
|
|
forceDisableMotion: false
|
|
forceDisableMotion: false
|
|
};
|
|
};
|
|
@@ -89,38 +89,16 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
|
|
return {
|
|
return {
|
|
...super.adapter,
|
|
...super.adapter,
|
|
collectPane: (): void => {
|
|
collectPane: (): void => {
|
|
- const { tabList, children } = this.props;
|
|
|
|
- if (Array.isArray(tabList) && tabList.length) {
|
|
|
|
- this.setState({ panes: tabList });
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- const panes = React.Children.map(children, (child: any) => {
|
|
|
|
- if (child) {
|
|
|
|
- const { tab, icon, disabled, itemKey, closable } = child.props;
|
|
|
|
- return { tab, icon, disabled, itemKey, closable };
|
|
|
|
- }
|
|
|
|
- return undefined;
|
|
|
|
- });
|
|
|
|
|
|
+ const panes = this.getPanes();
|
|
this.setState({ panes });
|
|
this.setState({ panes });
|
|
},
|
|
},
|
|
collectActiveKey: (): void => {
|
|
collectActiveKey: (): void => {
|
|
- let panes = [];
|
|
|
|
const { tabList, children, activeKey: propsActiveKey } = this.props;
|
|
const { tabList, children, activeKey: propsActiveKey } = this.props;
|
|
if (typeof propsActiveKey !== 'undefined') {
|
|
if (typeof propsActiveKey !== 'undefined') {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
const { activeKey } = this.state;
|
|
const { activeKey } = this.state;
|
|
- if (Array.isArray(tabList) && tabList.length) {
|
|
|
|
- panes = tabList;
|
|
|
|
- } else {
|
|
|
|
- panes = React.Children.map(children, (child: any) => {
|
|
|
|
- if (child) {
|
|
|
|
- const { tab, icon, disabled, itemKey, closable } = child.props;
|
|
|
|
- return { tab, icon, disabled, itemKey, closable };
|
|
|
|
- }
|
|
|
|
- return undefined;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ const panes = this.getPanes();
|
|
if (panes.findIndex(p => p.itemKey === activeKey) === -1) {
|
|
if (panes.findIndex(p => p.itemKey === activeKey) === -1) {
|
|
if (panes.length > 0) {
|
|
if (panes.length > 0) {
|
|
this.setState({ activeKey: panes[0].itemKey });
|
|
this.setState({ activeKey: panes[0].itemKey });
|
|
@@ -207,6 +185,20 @@ class Tabs extends BaseComponent<TabsProps, TabsState> {
|
|
this.contentRef = { current: ref };
|
|
this.contentRef = { current: ref };
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ getPanes = (): PlainTab[] => {
|
|
|
|
+ const { tabList, children } = this.props;
|
|
|
|
+ if (Array.isArray(tabList) && tabList.length) {
|
|
|
|
+ return tabList;
|
|
|
|
+ }
|
|
|
|
+ return React.Children.map(children, (child: any) => {
|
|
|
|
+ if (child) {
|
|
|
|
+ const { tab, icon, disabled, itemKey, closable } = child.props;
|
|
|
|
+ return { tab, icon, disabled, itemKey, closable };
|
|
|
|
+ }
|
|
|
|
+ return undefined;
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
onTabClick = (activeKey: string, event: MouseEvent<HTMLDivElement>): void => {
|
|
onTabClick = (activeKey: string, event: MouseEvent<HTMLDivElement>): void => {
|
|
this.foundation.handleTabClick(activeKey, event);
|
|
this.foundation.handleTabClick(activeKey, event);
|
|
};
|
|
};
|