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 db62807
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
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 db62807

Please sign in to comment.