Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OptionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const RefOptionList = React.forwardRef<RefOptionListProps, OptionListProps>((pro
if (loadingKeys.length) {
loadingKeys.forEach(loadingKey => {
const option = flattenOptions.find(opt => opt.value === loadingKey);
if (option.data.children) {
if (option.data.children || option.data.isLeaf === true) {
setLoadingKeys(keys => keys.filter(key => key !== loadingKey));
}
});
Expand Down
36 changes: 36 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/jsx-no-bind */

import React from 'react';
import { act } from 'react-dom/test-utils';
import { resetWarned } from 'rc-util/lib/warning';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { mount } from './enzyme';
Expand Down Expand Up @@ -603,6 +604,41 @@ describe('Cascader.Basic', () => {
jest.runAllTimers();
expect(loadData).toHaveBeenCalled();
});

it('change isLeaf back to true should not loop loading', async () => {
const Demo = () => {
const [options, setOptions] = React.useState([
{ value: 'zhejiang', label: 'Zhejiang', isLeaf: false },
]);

const loadData = () => {
Promise.resolve().then(() => {
act(() => {
setOptions([
{
value: 'zhejiang',
label: 'Zhejiang',
isLeaf: true,
},
]);
});
});
};

return <Cascader options={options} loadData={loadData} open />;
};

const wrapper = mount(<Demo />);
wrapper.find('.rc-cascader-menu-item-content').first().simulate('click');
expect(wrapper.exists('.rc-cascader-menu-item-loading')).toBeTruthy();

for (let i = 0; i < 3; i += 1) {
await Promise.resolve();
}
wrapper.update();

expect(wrapper.exists('.rc-cascader-menu-item-loading')).toBeFalsy();
});
});

// https://github.com/ant-design/ant-design/issues/9793
Expand Down