Skip to content

Commit

Permalink
feat(react): adjust component recognition priority (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jun 12, 2022
1 parent d705f56 commit bf4e035
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/react/src/components/ReactiveField.tsx
Expand Up @@ -24,6 +24,9 @@ const mergeChildren = (
)
}

const isValidComponent = (target: any) =>
target && (typeof target === 'object' || typeof target === 'function')

const renderChildren = (
children: RenderPropsChildren<GeneralField>,
field?: GeneralField,
Expand All @@ -42,15 +45,19 @@ const ReactiveInternal: React.FC<IReactiveFieldProps> = (props) => {
)
if (field.display !== 'visible') return null

const getComponent = (target: any) => {
return isValidComponent(target)
? target
: FormPath.getIn(components, target) ?? target
}

const renderDecorator = (children: React.ReactNode) => {
if (!field.decoratorType) {
return <Fragment>{children}</Fragment>
}
const finalComponent =
FormPath.getIn(components, field.decoratorType) ?? field.decoratorType

return React.createElement(
finalComponent,
getComponent(field.decoratorType),
toJS(field.decoratorProps),
children
)
Expand Down Expand Up @@ -83,10 +90,8 @@ const ReactiveInternal: React.FC<IReactiveFieldProps> = (props) => {
const readOnly = !isVoidField(field)
? field.pattern === 'readOnly'
: undefined
const finalComponent =
FormPath.getIn(components, field.componentType) ?? field.componentType
return React.createElement(
finalComponent,
getComponent(field.componentType),
{
disabled,
readOnly,
Expand Down

0 comments on commit bf4e035

Please sign in to comment.