Skip to content

Commit

Permalink
fix: 🐛 form disabled属性bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingyun2010 committed Dec 1, 2023
2 parents 5bd5860 + 4a296a3 commit 334f0e3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
6 changes: 3 additions & 3 deletions components/form/demo/typeByDivider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { Form } from 'at-console-components'
import { Store } from 'antd/lib/form/interface'
import { FormItemProps } from '..'
import { Store } from 'antd/lib/form/interface'
import { Form } from 'at-console-components'
import React from 'react'

const { useForm } = Form

Expand Down
50 changes: 50 additions & 0 deletions components/form/demo/typeBySubTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { FormItemProps } from '..'
import { Store } from 'antd/lib/form/interface'
import { Form } from 'at-console-components'
import React from 'react'

const { useForm } = Form

export default function BaseDemo() {
const [form] = useForm()
const baseItems: FormItemProps[] = [
{
label: '介绍',
type: 'subTitle',
},
{
name: 'name',
label: '姓名',
},
{
name: 'sex',
label: '性别',
},
{
label: '其他',
type: 'subTitle',
},
{
name: 'website',
label: '个人主页',
},
]

return (
<Form
items={baseItems}
form={form}
title="表单标题"
// eslint-disable-next-line no-console
onFinish={(values: Store) =>
new Promise(resolve => {
setTimeout(() => {
// eslint-disable-next-line no-console
console.log('BaseDemo', values)
resolve(values)
}, 1000)
})
}
/>
)
}
11 changes: 10 additions & 1 deletion components/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ interface FormCommonProps {

// 信息脱敏
desensitize?: DesensitizeType | string

// 标题
title?: string
}

export interface FormItemProps extends Omit<AntdFormItemProps, 'children'>, FormCommonProps {
Expand All @@ -87,7 +90,7 @@ export interface FormItemProps extends Omit<AntdFormItemProps, 'children'>, Form
suffix?: ReactNode | ((fieldsValue: Store) => ReactNode)

// Default render
type?: 'divider'
type?: 'divider' | 'subTitle'

// disabled
disabled?: boolean
Expand Down Expand Up @@ -128,6 +131,10 @@ const RenderChild: FC<Pick<FormItemProps, 'suffix' | 'type' | 'label' | 'disable
return <Divider orientation="left">{label}</Divider>
}

if (type === 'subTitle') {
return <h3>{label}</h3>
}

if (suffix) {
return (
<Space>
Expand All @@ -154,6 +161,7 @@ const InternalForm: ForwardRefRenderFunction<FormInstance, FormProps> = (
onReset: onResetInternal,
isView = false,
form,
title,
layoutCol = { span: 24 },
initialValues: initialValuesInternal,
placeholder: placeholderInternal = '-',
Expand Down Expand Up @@ -390,6 +398,7 @@ const InternalForm: ForwardRefRenderFunction<FormInstance, FormProps> = (
// Better use Button loading when submit, but we can't control button
return (
<Spin spinning={loading}>
{title && <h2>{title}</h2>}
<AntdForm
form={formInsatce}
onFinish={onFinish}
Expand Down
6 changes: 5 additions & 1 deletion components/form/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ group:

<code src="./demo/typeByDivider.tsx" />

##### SubTitle

<code src="./demo/typeBySubTitle.tsx" />

### 参数

| 属性 | 描述 | 类型 | 默认值 |
Expand All @@ -79,6 +83,6 @@ group:
| layoutCol | 布局 | [ColProps](https://ant.design/components/grid/#Col) | Form `layoutCol` |
| extraNames | 额外的 name | `NamePath[]` | - |
| placeholder | 占位符(View 模式下数据为 `null` `undefined` `''` 显示的文字) | `string` | `-` |
| type | 默认类型 | `divider` | `-` |
| type | 默认类型 | `divider` `subTitle` | `-` |
| suffix | 设置后置标签 | `ReactNode \| (fieldValue: StoreValue, fieldsValue: Store) => ReactNode` | `-` |
| tips | 设置提示标签 | `ReactNode \| (fieldValue: StoreValue, fieldsValue: Store) => ReactNode` | `-` |

0 comments on commit 334f0e3

Please sign in to comment.