Skip to content

Commit 9d16e4f

Browse files
myGitZoneyanchanglu
andauthored
fix: children获取不到,undefined报错 (#260)
* fix(清空选项时动态修改options): 导致children获取不到,undefined报错 * fix(清空选项时动态修改options): 添加测试用例 * fix(清空选项时动态修改options): 修改测试用例 * fix(清空选项时动态修改options): 修改测试用例,bug与异步加载数据无关。 Co-authored-by: yanchanglu <[email protected]>
1 parent d6e637c commit 9d16e4f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/OptionList/useKeyboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default (
2626
const len = activeValueCells.length;
2727

2828
// Fill validate active value cells and index
29-
for (let i = 0; i < len; i += 1) {
29+
for (let i = 0; i < len && currentOptions; i += 1) {
3030
// Mark the active index for current options
3131
const nextActiveIndex = currentOptions.findIndex(
3232
option => option[fieldNames.value] === activeValueCells[i],

tests/selector.spec.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { mount } from './enzyme';
33
import Cascader from '../src';
4+
import { addressOptions } from './demoOptions';
45

56
describe('Cascader.Selector', () => {
67
describe('clear all', () => {
@@ -32,4 +33,22 @@ describe('Cascader.Selector', () => {
3233
wrapper.find('.rc-cascader-selection-item-remove-icon').first().simulate('click');
3334
expect(onChange).toHaveBeenCalledWith([['exist']], expect.anything());
3435
});
36+
37+
it('when selected modify options', () => {
38+
const wrapper = mount(<Cascader options={addressOptions} open />);
39+
40+
// First column click
41+
wrapper.find('.rc-cascader-menu-item-content').first().simulate('click');
42+
wrapper.update();
43+
44+
// Second column click
45+
wrapper.find('.rc-cascader-menu-item-content').last().simulate('click');
46+
wrapper.update();
47+
48+
wrapper.setProps({
49+
options: [{ label: '福建', value: 'fj', isLeaf: false }],
50+
});
51+
52+
wrapper.update();
53+
});
3554
});

0 commit comments

Comments
 (0)