Skip to content

Commit f5de46d

Browse files
committed
fix(blockheader): change comment and showCollapse judge
1 parent e98a4b8 commit f5de46d

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
| expand | 当前展开状态 | `boolean` | |
4343
| spaceBottom | 自定义下边距,优先级高于 hasBottom | `number` | `16` |
4444
| children | 展开/收起的内容 | `React.ReactNode` | - |

src/blockHeader/index.tsx

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

Comments
 (0)