Skip to content

Commit

Permalink
fix: fix Table indent bug when tree data is empty and expandIcon is f…
Browse files Browse the repository at this point in the history
…alse #2425 (#2430)

Co-authored-by: shijia.me <shijia.me@bytedance.com>
Co-authored-by: pointhalo <88709023+pointhalo@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent a4a95a4 commit c19fc1a
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 159 deletions.
5 changes: 4 additions & 1 deletion packages/semi-ui/table/Body/BaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ export default class TableRow extends BaseComponent<BaseRowProps, Record<string,
// Only the first data row will be indented
if (level != null && columnIndex === firstIndex) {
expandableProps.indent = level;
const isBool = typeof expandIcon === 'boolean';
const hasExpandIcon = expandIcon !== false || !isBool && expandIcon !== null;

if (!expandableRow && hideExpandedColumn) {
// 如果 expandIcon 为空,不需要 indent
if (!expandableRow && hideExpandedColumn && hasExpandIcon) {
expandableProps.indent = level + 1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/semi-ui/table/_story/table.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export {
DndKitDrag,
FixedOnGroupedRowClassName,
FixedVirtualizedRef,
RowSelectionOnCell
RowSelectionOnCell,
FixedIndent
} from './v2';
export { default as FixSelectAll325 } from './Demos/rowSelection';

Expand Down
54 changes: 54 additions & 0 deletions packages/semi-ui/table/_story/v2/FixedIndent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { Table } from '@douyinfe/semi-ui';

export default function App() {
const columns = [
{
title: 'Key',
dataIndex: 'dataKey',
key: 'dataKey',
},
{
title: '名称',
dataIndex: 'name',
key: 'name',
width: 200,
},
{
title: '数据类型',
dataIndex: 'type',
key: 'type',
width: 400,
},
];
const data = [
{
key: 99,
dataKey: 99,
name: 'row 99',
children: [],
},
{
key: 2,
dataKey: 'text_info',
name: '文本信息',
type: 'Object 对象',
description: '视频的元信息',
default: '无',
children: [
{
key: 21,
dataKey: 'title',
name: '视频标题',
type: 'String 字符串',
description: '视频的标题',
default: '无',
},
],
},
];
return <div>
<Table expandIcon={false} defaultExpandAllRows columns={columns} dataSource={data} />
<Table defaultExpandAllRows columns={columns} dataSource={data} />
</div>;
}
1 change: 1 addition & 0 deletions packages/semi-ui/table/_story/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ export { default as DndKitDrag } from './DndKitDrag';
export { default as FixedOnGroupedRowClassName } from './FixedOnGroupedRowClassName';
export { default as FixedVirtualizedRef } from './FixedVirtualizedRef';
export { default as RowSelectionOnCell } from './RowSelectionOnCell';
export { default as FixedIndent } from './FixedIndent';
Loading

0 comments on commit c19fc1a

Please sign in to comment.