From 886899f9249580b79db7fb397241d28f879c817f Mon Sep 17 00:00:00 2001
From: hemengke1997 <49073282+hemengke1997@users.noreply.github.com>
Date: Fri, 6 Jan 2023 16:44:10 +0800
Subject: [PATCH] fix: `defaultWidth` not work
---
example/src/App.tsx | 5 +++--
example/tsconfig.json | 2 +-
src/ResizableHeader.tsx | 5 ++++-
src/useAntdResizableHeader.tsx | 2 +-
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/example/src/App.tsx b/example/src/App.tsx
index 8e0a559..9c3e8b1 100644
--- a/example/src/App.tsx
+++ b/example/src/App.tsx
@@ -5,7 +5,7 @@ import './App.css'
import { useAntdResizableHeader } from '@minko-fe/use-antd-resizable-header'
import '@minko-fe/use-antd-resizable-header/dist/style.css'
-const tcls = [
+const tcls: any[] = [
{
title: '333',
dataIndex: 'name',
@@ -149,7 +149,7 @@ function App() {
{
title: 'test render',
dataIndex: 'testRender',
- width: 333,
+ width: 111,
render: () => {
return
setX()}>{x}
},
@@ -173,6 +173,7 @@ function App() {
tableWidth: tp,
} = useAntdResizableHeader({
columns: proColumns,
+ defaultWidth: 444,
columnsState: {
persistenceType: 'localStorage',
persistenceKey: 'fds',
diff --git a/example/tsconfig.json b/example/tsconfig.json
index 11f1ece..f756463 100644
--- a/example/tsconfig.json
+++ b/example/tsconfig.json
@@ -16,5 +16,5 @@
"jsx": "react",
"noImplicitAny": false
},
- "include": ["./src", "./vite.config.ts"],
+ "include": ["./src", "./vite.config.ts"]
}
diff --git a/src/ResizableHeader.tsx b/src/ResizableHeader.tsx
index f2ff9ee..96a1777 100644
--- a/src/ResizableHeader.tsx
+++ b/src/ResizableHeader.tsx
@@ -97,7 +97,10 @@ const ResizableHeader: FC = (props) => {
const isSimpleChildren = () => {
if (Array.isArray(children)) {
- return isString(children[children.length - 1])
+ const lastChild = children[children.length - 1]
+ if (lastChild) {
+ return isString(lastChild) || lastChild.props?.ellipsis || isString(lastChild.props?.label)
+ }
}
return false
}
diff --git a/src/useAntdResizableHeader.tsx b/src/useAntdResizableHeader.tsx
index dabe490..c817c28 100644
--- a/src/useAntdResizableHeader.tsx
+++ b/src/useAntdResizableHeader.tsx
@@ -201,7 +201,7 @@ function useAntdResizableHeader>
loop(cls[i].children as ColumnType[])
} else {
if (!cls[i].hideInTable) {
- width += Number(cls[i].width) || Number(columns?.[columns.length - 1].width) || defaultWidth
+ width += Number(cls[i].width) || defaultWidth
}
}
}