@@ -38,15 +38,15 @@ export interface IBlockHeaderProps {
3838 className ?: string ;
3939 /** 标题的样式类名 */
4040 style ?: React . CSSProperties ;
41- // 展示内容(children)的样式类名
41+ /** 展示内容(children)的样式类名 */
4242 contentClassName ?: string ;
43- // 展示内容(children)的样式
43+ /** 展示内容(children)的样式 */
4444 contentStyle ?: React . CSSProperties ;
4545 /** 是否显示背景, 默认 true */
4646 background ?: boolean ;
4747 /** 当前展开状态 */
4848 expand ?: boolean ;
49- /** 是否默认展开内容, 默认 true */
49+ /** 是否默认展开内容, 默认为 undefined */
5050 defaultExpand ?: boolean ;
5151 /** 展开/收起的内容 */
5252 children ?: ReactNode ;
@@ -82,7 +82,9 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
8282
8383 const currentExpand = isControlled ( props ) ? expand : internalExpand ;
8484
85- const showCollapse = typeof expand === 'boolean' || typeof defaultExpand === 'boolean' ;
85+ // 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
86+ const showCollapse =
87+ ( typeof expand === 'boolean' || typeof defaultExpand === 'boolean' ) && children ;
8688
8789 const tooltipProps = toTooltipProps ( tooltip ) ;
8890
@@ -101,7 +103,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
101103 < div
102104 className = { classNames ( preTitleRowCls , `${ preTitleRowCls } --${ size } ` , {
103105 [ `${ preTitleRowCls } --background` ] : background ,
104- [ `${ preTitleRowCls } --pointer` ] : showCollapse && children ,
106+ [ `${ preTitleRowCls } --pointer` ] : showCollapse ,
105107 } ) }
106108 onClick = { ( ) => showCollapse && handleExpand ( ! currentExpand ) }
107109 >
@@ -122,7 +124,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
122124 { description ? < div className = { `title__description` } > { description } </ div > : null }
123125 </ div >
124126 { addonAfter && < div className = { `title__addon-after` } > { addonAfter } </ div > }
125- { children && showCollapse && (
127+ { showCollapse && (
126128 < div className = { `title__collapse` } >
127129 < div className = "collapse__text" > { currentExpand ? '收起' : '展开' } </ div >
128130 < UpOutlined
0 commit comments