Skip to content

Commit

Permalink
feat: 变更extra的类型
Browse files Browse the repository at this point in the history
  • Loading branch information
吴文达 committed Jul 5, 2023
1 parent 6337f96 commit 209791b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/form/form-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export type FormItemProps = Pick<
ListItemProps,
'style' | 'extra' | 'clickable' | 'arrow' | 'description'
> & {
label?: React.ReactNode
extra?: React.ReactNode | ((val: any) => React.ReactNode) ,
label?: React.ReactNode
help?: React.ReactNode
hasFeedback?: boolean
required?: boolean
Expand Down Expand Up @@ -301,6 +302,7 @@ export const FormItem: FC<FormItemProps> = props => {

function renderLayout(
baseChildren: React.ReactNode,
value?: any,
fieldId?: string,
meta?: Meta,
isRequired?: boolean
Expand Down Expand Up @@ -332,13 +334,20 @@ export const FormItem: FC<FormItemProps> = props => {
curWarnings
)

const renderExtra = ()=> {
if(typeof extra === 'function'){
return extra(value)
}
return extra
}

return withNativeProps(
props,
<FormItemLayout
className={className}
style={style}
label={label}
extra={extra}
extra={renderExtra()}
help={help}
description={description}
required={isRequired}
Expand Down Expand Up @@ -499,7 +508,7 @@ export const FormItem: FC<FormItemProps> = props => {
childNode = children
}

return renderLayout(childNode, fieldId, meta, isRequired)
return renderLayout(childNode,control.value, fieldId, meta, isRequired)
}}
</Field>
)
Expand Down

0 comments on commit 209791b

Please sign in to comment.