Skip to content

Commit e432b20

Browse files
committed
fix(blockheader): change comment and showCollapse judge
1 parent 673845b commit e432b20

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/blockHeader/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ demo:
3838
| contentClassName | 展示内容的样式类名 | `string` | - |
3939
| contentStyle | 展示内容的样式 | `React.CSSProperties` | - |
4040
| background | 是否显示背景 | `boolean` | `true` |
41-
| defaultExpand | 是否默认展开内容 | `boolean` | `true` |
41+
| defaultExpand | 是否默认展开内容 | `boolean` | - |
4242
| hasBottom | 是否有默认下边距 16px | `boolean` | `false` |
4343
| expand | 当前展开状态 | `boolean` | |
4444
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `0` |

src/blockHeader/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)