mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-04 21:08:55 +08:00
fix: Tree编辑子节点无法取消的情况 (#6079)
This commit is contained in:
parent
3b8809233c
commit
ff88c35e1c
@ -686,10 +686,15 @@ export class TreeSelector extends React.Component<
|
||||
|
||||
@autobind
|
||||
handleCancel() {
|
||||
const {flattenedOptions} = this.state;
|
||||
const flattenedOptionsWithoutAdding = flattenedOptions.filter(
|
||||
item => !item.isAdding
|
||||
);
|
||||
this.setState({
|
||||
inputValue: '',
|
||||
isAdding: false,
|
||||
isEditing: false
|
||||
isEditing: false,
|
||||
flattenedOptions: flattenedOptionsWithoutAdding
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -375,3 +375,58 @@ test('Tree defer load data', async () => {
|
||||
'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()
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user