Skip to content

Commit

Permalink
fix: crash when exist options with same value on different levels (#258)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff.Yuan <[email protected]>
  • Loading branch information
cbozi and cbozi authored Mar 15, 2022
1 parent b354d6a commit 8004012
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useSearchOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { DefaultOptionType, ShowSearchType, InternalFieldNames } from '../Cascader';
import * as React from 'react';
import { VALUE_SPLIT } from '../utils/commonUtil';

export const SEARCH_MARK = '__rc_cascader_search_mark__';

Expand Down Expand Up @@ -52,6 +53,9 @@ export default (
prefixCls,
fieldNames,
),
[fieldNames.value as 'value']: connectedPathOptions
.map(pathOption => pathOption[fieldNames.value])
.join(VALUE_SPLIT),
[SEARCH_MARK]: connectedPathOptions,
});
}
Expand Down
9 changes: 9 additions & 0 deletions tests/search.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import KeyCode from 'rc-util/lib/KeyCode';
import { resetWarned } from 'rc-util/lib/warning';
import { mount, ReactWrapper } from './enzyme';
import Cascader from '../src';
import { optionsForActiveMenuItems } from './demoOptions';

describe('Cascader.Search', () => {
function doSearch(wrapper: ReactWrapper, search: string) {
Expand Down Expand Up @@ -190,4 +191,12 @@ describe('Cascader.Search', () => {
wrapper.find('.rc-cascader-menu-item').first().simulate('mousedown');
expect(onChange).toHaveBeenCalledWith([['bamboo', 'little', 'fish']], expect.anything());
});

it('should not crash when exist options with same value on different levels', () => {
const wrapper = mount(<Cascader options={optionsForActiveMenuItems} />);

doSearch(wrapper, '1');
wrapper.find('.rc-cascader-menu-item').first().simulate('click');
doSearch(wrapper, '1');
});
});

1 comment on commit 8004012

@vercel
Copy link

@vercel vercel bot commented on 8004012 Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.