Skip to content

Commit

Permalink
fix: defaultWidth not work
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Jan 6, 2023
1 parent feb06f3 commit 886899f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -149,7 +149,7 @@ function App() {
{
title: 'test render',
dataIndex: 'testRender',
width: 333,
width: 111,
render: () => {
return <div onClick={() => setX()}>{x}</div>
},
Expand All @@ -173,6 +173,7 @@ function App() {
tableWidth: tp,
} = useAntdResizableHeader({
columns: proColumns,
defaultWidth: 444,
columnsState: {
persistenceType: 'localStorage',
persistenceKey: 'fds',
Expand Down
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"jsx": "react",
"noImplicitAny": false
},
"include": ["./src", "./vite.config.ts"],
"include": ["./src", "./vite.config.ts"]
}
5 changes: 4 additions & 1 deletion src/ResizableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ const ResizableHeader: FC<ComponentProp> = (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
}
Expand Down
2 changes: 1 addition & 1 deletion src/useAntdResizableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function useAntdResizableHeader<ColumnType extends ColumnOriginType<ColumnType>>
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
}
}
}
Expand Down

0 comments on commit 886899f

Please sign in to comment.