chore: 不自动包裹 asFormItem (#2275)

* 不自动包裹 asFormItem

* 改个名字
This commit is contained in:
liaoxuezhi 2021-07-14 16:37:54 +08:00 committed by GitHub
parent b5c7fabbfe
commit b7036a2930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View File

@ -87,6 +87,7 @@ export default {
{
name: 'a',
asFormItem: true,
children: ({value, onChange}) => (
<div>
<p>这是使用 children 的方式也无需注册</p>
@ -129,6 +130,7 @@ export default {
},
{
label: '',
asFormItem: true,
children: ({render}) => (
<div>
<p>组合现有组件</p>
@ -158,6 +160,7 @@ export default {
{
name: 'c',
label: '',
asFormItem: true,
component: ({render, value, onChange, name}) => {
function handleXChange(x) {
value = {

View File

@ -121,12 +121,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
} else {
// 自定义组件如果在节点设置了 label name 什么的,就用 formItem 包一层
// 至少自动支持了 valdiations, label, description 等逻辑。
if (
schema.children &&
!schema.component &&
(schema.asFormItem ||
(props.formStore && (schema.name || schema.hasOwnProperty('label'))))
) {
if (schema.children && !schema.component && schema.asFormItem) {
schema.component = PlaceholderComponent;
schema.renderChildren = schema.children;
delete schema.children;
@ -134,9 +129,8 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
if (
schema.component &&
!schema.component.wrapAsFormItem &&
(schema.asFormItem ||
(props.formStore && (schema.name || schema.hasOwnProperty('label'))))
!schema.component.wrapedAsFormItem &&
schema.asFormItem
) {
const cache = componentCache.get(schema.component);
@ -148,7 +142,7 @@ export class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
...schema.asFormItem
})(schema.component);
componentCache.set(schema.component, cache);
cache.wrapAsFormItem = true;
cache.wrapedAsFormItem = true;
schema.component = cache;
}
}