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

[Bug Report] 基于 useField 做的 arrayItems,调用 remove 方法删除 item 时未生效 #4036

Open
1 task
liuguibin0828 opened this issue Nov 28, 2023 · 1 comment

Comments

@liuguibin0828
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

ArrayBase.Remove = React.forwardRef((props, ref) => {
const index = useIndex(props.index)
const self = useField()
const array = useArray()
const prefixCls = usePrefixCls('formily-array-base')
if (!array) return null
if (array.field?.pattern !== 'editable') return null
return (
<Button
ref={ref}
type="text"
{...props}
disabled={self?.disabled}
className={cls(
${prefixCls}-remove,
self?.disabled ? ${prefixCls}-remove-disabled : '',
props.className
)}
onClick={(e) => {
if (self?.disabled) return
e.stopPropagation()
if (props.onClick) {
props.onClick(e)
if (e.defaultPrevented) return
}
console.log('remove inner', index);
array.field?.remove?.(index!)
array.props?.onRemove?.(index!)
}}
>
{isUndef(props.prefix) ? : props.prefix}
{props.title || self.title}

)
})

<SchemaField.Array
name="string_array"
title="字符串数组"
x-decorator="FormItem"
x-component="ArrayItems"
x-component-props={{
onRemove: (index) => {
console.log('remove effet', index);
}
}}
>
<SchemaField.Void>
<SchemaField.Void
x-decorator="FormItem"
x-component="ArrayItems.SortHandle"
/>
<SchemaField.String
x-decorator="FormItem"
required
name="input"
x-component="Input"
/>
<SchemaField.Void
x-decorator="FormItem"
x-component="ArrayItems.Remove"
/>
<SchemaField.Void
x-decorator="FormItem"
x-component="ArrayItems.Copy"
/>
</SchemaField.Void>
<SchemaField.Void
x-component="ArrayItems.Addition"
title="添加条目"
/>
</SchemaField.Array>

What is expected?

点击删除,关联 item 被销毁

What is actually happening?

点击删除,关联 item 仍然存在

Package

@formily/react@2.2.23


@YUEchn
Copy link

YUEchn commented Sep 19, 2024

I met the same issue, could you please how you solved it? @liuguibin0828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants