fix: Tree编辑子节点无法取消的情况 (#6079)

This commit is contained in:
meerkat 2023-01-17 14:21:42 +08:00 committed by GitHub
parent 3b8809233c
commit ff88c35e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 1 deletions

View File

@ -686,10 +686,15 @@ export class TreeSelector extends React.Component<
@autobind @autobind
handleCancel() { handleCancel() {
const {flattenedOptions} = this.state;
const flattenedOptionsWithoutAdding = flattenedOptions.filter(
item => !item.isAdding
);
this.setState({ this.setState({
inputValue: '', inputValue: '',
isAdding: false, isAdding: false,
isEditing: false isEditing: false,
flattenedOptions: flattenedOptionsWithoutAdding
}); });
} }

View File

@ -375,3 +375,58 @@ test('Tree defer load data', async () => {
'is-folded' 'is-folded'
); );
}); });
test('Tree: add child & cancel', async () => {
const {container, getByText} = render(
amisRender(
{
type: 'form',
api: '/api/mock2/form/saveForm',
body: [
{
type: 'input-tree',
name: 'tree',
label: 'Tree',
creatable: true,
removable: true,
editable: true,
options: [
{
label: 'Folder A',
value: 1,
children: [
{
label: 'file A',
value: 2
},
{
label: 'file B',
value: 3
}
]
},
{
label: 'file C',
value: 4
},
{
label: 'file D',
value: 5
}
]
}
]
},
{},
makeEnv({})
)
);
const targetNode = container.querySelector('.cxd-Tree-addTopBtn')!;
fireEvent.click(targetNode);
await waitFor(() => container.querySelector('input'));
fireEvent.click(container.querySelector('[icon="close"]')!);
await waitFor(() =>
expect(!!container.querySelector('[icon="close"]')).toBeFalsy()
);
});