Skip to content

Commit

Permalink
feat: (Form.Array) add onAdd prop (#4969)
Browse files Browse the repository at this point in the history
* feat: 添加 onAdd

* feat: doc

* feat: doc
  • Loading branch information
crazyair authored Mar 24, 2022
1 parent 3b724e6 commit 05b1762
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/form/demos/demo-array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default () => {

<Form.Array
name='contacts'
onAdd={operation => operation.add({ name: '张三' })}
renderAdd={() => (
<span>
<AddCircleOutline /> 添加
Expand Down
3 changes: 2 additions & 1 deletion src/components/form/form-array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface FormArrayProps {
field: FormArrayField,
operation: FormArrayOperation
) => ReactNode
onAdd?: (operation: FormArrayOperation) => void
renderAdd?: () => ReactNode
children: (
fields: FormArrayField[],
Expand Down Expand Up @@ -54,7 +55,7 @@ export const FormArray: React.FC<FormArrayProps> = props => {
<List.Item
className='adm-form-list-operation'
onClick={() => {
operation.add()
props.onAdd ? props.onAdd(operation) : operation.add()
}}
arrow={false}
>
Expand Down
1 change: 1 addition & 0 deletions src/components/form/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Provides array management for fields.
| children | Render function. | `(fields: FormArrayField[], operation: FormArrayOperation) => ReactElement[]` | - |
| renderHeader | Render the header of each field. | `(field: FormArrayField, operation: FormArrayOperation) => ReactNode` | - |
| renderAdd | Render the content of add button. | `() => ReactNode` | - |
| onAdd | Custom add function. | `(operation: FormArrayOperation) => void` | - |
| initialValue | Config sub default value. Form `initialValues` get higher priority when conflict. | `any[]` | - |

### FormArrayField
Expand Down
1 change: 1 addition & 0 deletions src/components/form/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Form 通过增量更新方式,只更新被修改的字段相关组件以达到
| children | 渲染函数 | `(fields: FormArrayField[], operation: FormArrayOperation) => ReactElement[]` | - |
| renderHeader | 渲染每一项的头部内容 | `(field: FormArrayField, operation: FormArrayOperation) => ReactNode` | - |
| renderAdd | 渲染添加按钮的文案 | `() => ReactNode` | - |
| onAdd | 自定义添加方法 | `(operation: FormArrayOperation) => void` | - |
| initialValue | 设置子元素默认值,如果与 Form 的 `initialValues` 冲突则以 Form 为准 | `any[]` | - |

### FormArrayField
Expand Down

0 comments on commit 05b1762

Please sign in to comment.