From 4f0862929db97d9f6785a6aeb43bc79c6cf4011b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E6=8C=AF=E5=B7=9D?= Date: Thu, 11 Mar 2021 23:26:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E5=BD=93Panel=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Tabs/PanelList/index.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/Tabs/PanelList/index.js b/src/components/Tabs/PanelList/index.js index 2b9bebf..0673bad 100644 --- a/src/components/Tabs/PanelList/index.js +++ b/src/components/Tabs/PanelList/index.js @@ -35,7 +35,7 @@ export default class PanelList extends Component { constructor(props) { super(props); const { children, activeIndex } = props; - this.childrenCount = React.Children.count(children); + this.childrenCount = (children || []).filter(v => !!v); const panelWidthPerCent = 100 / this.childrenCount; const panelWrapperPerCent = 100 * this.childrenCount; const panelWrapperTranslation = activeIndex * panelWidthPerCent; @@ -194,15 +194,19 @@ export default class PanelList extends Component { } self[`panelIscroll-${index}`] = React.createRef(); - return React.cloneElement(child, { - key: index, - tabIndex: index, - active: index === activeIndex, - panelWidthPerCent, - panelRef: panelRef, - myIscroll: self[`panelIscroll-${index}`], - ...props, - }) + if (child) { + return React.cloneElement(child, { + key: index, + tabIndex: index, + active: index === activeIndex, + panelWidthPerCent, + panelRef: panelRef, + myIscroll: self[`panelIscroll-${index}`], + ...props, + }) + } else { + return null + } }) }