@@ -36,15 +36,15 @@ export interface IBlockHeaderProps {
3636 className ?: string ;
3737 /** 标题的样式类名 */
3838 style ?: React . CSSProperties ;
39- // 展示内容(children)的样式类名
39+ /** 展示内容(children)的样式类名 */
4040 contentClassName ?: string ;
41- // 展示内容(children)的样式
41+ /** 展示内容(children)的样式 */
4242 contentStyle ?: React . CSSProperties ;
4343 /** 是否显示背景, 默认 true */
4444 background ?: boolean ;
4545 /** 当前展开状态 */
4646 expand ?: boolean ;
47- /** 是否默认展开内容, 默认 true */
47+ /** 是否默认展开内容, 默认为 undefined */
4848 defaultExpand ?: boolean ;
4949 /** 展开/收起的内容 */
5050 children ?: ReactNode ;
@@ -79,7 +79,9 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
7979
8080 const currentExpand = isControlled ( props ) ? expand : internalExpand ;
8181
82- const showCollapse = typeof expand === 'boolean' || typeof defaultExpand === 'boolean' ;
82+ // 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
83+ const showCollapse =
84+ ( typeof expand === 'boolean' || typeof defaultExpand === 'boolean' ) && children ;
8385
8486 const tooltipProps = toTooltipProps ( tooltip ) ;
8587
@@ -97,7 +99,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
9799 < div
98100 className = { classNames ( preTitleRowCls , `${ preTitleRowCls } --${ size } ` , {
99101 [ `${ preTitleRowCls } --background` ] : background ,
100- [ `${ preTitleRowCls } --pointer` ] : showCollapse && children ,
102+ [ `${ preTitleRowCls } --pointer` ] : showCollapse ,
101103 } ) }
102104 onClick = { ( ) => showCollapse && handleExpand ( ! currentExpand ) }
103105 >
@@ -118,7 +120,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
118120 { description ? < div className = { `title__description` } > { description } </ div > : null }
119121 </ div >
120122 { addonAfter && < div className = { `title__addon-after` } > { addonAfter } </ div > }
121- { children && showCollapse && (
123+ { showCollapse && (
122124 < div className = { `title__collapse` } >
123125 < div className = "collapse__text" > { currentExpand ? '收起' : '展开' } </ div >
124126 < UpOutlined
0 commit comments