Skip to content

Commit

Permalink
fix: add prefixCls to getReadCellContent
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Mar 25, 2024
1 parent 6d8992e commit 547e5d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
13 changes: 0 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
# [1.1.0](https://github.com/linxianxi/antd-table-editable/compare/v1.0.0...v1.1.0) (2024-03-25)


### Features

* v1.0.1 ([8b2b30a](https://github.com/linxianxi/antd-table-editable/commit/8b2b30aa6feb04fd45d8caf81ae3ffca9cc6b942))

# 1.0.0 (2024-03-25)


### Features

* v1.0.0 ([081fa26](https://github.com/linxianxi/antd-table-editable/commit/081fa26987975582752b2f1647132e3f99a22f57))
2 changes: 1 addition & 1 deletion src/hooks/useCellEditable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function useCellEditable<RecordType>({
) => {
const node =
mode === 'read' ? (
getReadCellContent(children, content)
getReadCellContent(children, content, prefixCls)
) : (
<Form
form={form}
Expand Down
26 changes: 9 additions & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export function getField(key?: ColumnType<any>['key'], dataIndex?: ColumnType<an
* 这里也进行处理一下
* https://github.com/react-component/table/blob/master/src/Cell/index.tsx#L233
*/
export function getReadCellContent(children: React.ReactNode[], content: React.ReactNode) {
export function getReadCellContent(
children: React.ReactNode[],
content: React.ReactNode,
prefixCls: string,
) {
/**
* 取第一位,第 0 位是展开符,目前先不支持
* https://github.com/react-component/table/blob/master/src/Cell/index.tsx#L254
*/
const child = children[1];
if (React.isValidElement(child) && child.props.className?.includes('ant-table-cell-content')) {
const finalContent = (content as any)?.[1]?.props?.className?.includes('ant-table-cell-content')
if (React.isValidElement(child) && child.props.className?.includes(`${prefixCls}-cell-content`)) {
const finalContent = (content as any)?.[1]?.props?.className?.includes(
`${prefixCls}-cell-content`,
)
? (content as any)[1].props.children
: content;

Expand All @@ -40,17 +46,3 @@ export function getReadCellContent(children: React.ReactNode[], content: React.R
return content;
}
}

// 从 value 得到对应的文本
export function getCascaderLabel(value?: (string | number)[], options?: Record<string, any>[]) {
return value
?.reduce<Record<string, any>>((total, i, index) => {
const option = (index === 0 ? options : total[total.length - 1]?.children)?.find(
(op: Record<string, any>) => op.value === i,
);
total.push(option || i);
return total;
}, [])
.map((i: any) => i.label || i)
.join(' / ');
}

0 comments on commit 547e5d4

Please sign in to comment.