Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 变更extra的类型 #6237

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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