@@ -38,15 +38,15 @@ export interface IBlockHeaderProps {
38
38
className ?: string ;
39
39
/** 标题的样式类名 */
40
40
style ?: React . CSSProperties ;
41
- // 展示内容(children)的样式类名
41
+ /** 展示内容(children)的样式类名 */
42
42
contentClassName ?: string ;
43
- // 展示内容(children)的样式
43
+ /** 展示内容(children)的样式 */
44
44
contentStyle ?: React . CSSProperties ;
45
45
/** 是否显示背景, 默认 true */
46
46
background ?: boolean ;
47
47
/** 当前展开状态 */
48
48
expand ?: boolean ;
49
- /** 是否默认展开内容, 默认 true */
49
+ /** 是否默认展开内容, 默认为 undefined */
50
50
defaultExpand ?: boolean ;
51
51
/** 展开/收起的内容 */
52
52
children ?: ReactNode ;
@@ -82,7 +82,9 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
82
82
83
83
const currentExpand = isControlled ( props ) ? expand : internalExpand ;
84
84
85
- const showCollapse = typeof expand === 'boolean' || typeof defaultExpand === 'boolean' ;
85
+ // 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
86
+ const showCollapse =
87
+ ( typeof expand === 'boolean' || typeof defaultExpand === 'boolean' ) && children ;
86
88
87
89
const tooltipProps = toTooltipProps ( tooltip ) ;
88
90
@@ -101,7 +103,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
101
103
< div
102
104
className = { classNames ( preTitleRowCls , `${ preTitleRowCls } --${ size } ` , {
103
105
[ `${ preTitleRowCls } --background` ] : background ,
104
- [ `${ preTitleRowCls } --pointer` ] : showCollapse && children ,
106
+ [ `${ preTitleRowCls } --pointer` ] : showCollapse ,
105
107
} ) }
106
108
onClick = { ( ) => showCollapse && handleExpand ( ! currentExpand ) }
107
109
>
@@ -122,7 +124,7 @@ const BlockHeader: React.FC<IBlockHeaderProps> = function (props) {
122
124
{ description ? < div className = { `title__description` } > { description } </ div > : null }
123
125
</ div >
124
126
{ addonAfter && < div className = { `title__addon-after` } > { addonAfter } </ div > }
125
- { children && showCollapse && (
127
+ { showCollapse && (
126
128
< div className = { `title__collapse` } >
127
129
< div className = "collapse__text" > { currentExpand ? '收起' : '展开' } </ div >
128
130
< UpOutlined
0 commit comments