Skip to content

Commit 91bb98a

Browse files
committed
chore: fix logic
1 parent 83b315e commit 91bb98a

2 files changed

Lines changed: 18 additions & 31 deletions

File tree

src/OptionList/CacheContent.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/OptionList/List.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { clsx } from 'clsx';
33
import type { useBaseProps } from '@rc-component/select';
44
import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
55
import * as React from 'react';
6+
import useMemo from '@rc-component/util/lib/hooks/useMemo';
67
import type { DefaultOptionType, LegacyKey, SingleValueType } from '../Cascader';
78
import CascaderContext from '../context';
89
import {
@@ -14,7 +15,6 @@ import {
1415
toPathValueStr,
1516
} from '../utils/commonUtil';
1617
import { toPathOptions } from '../utils/treeUtil';
17-
import CacheContent from './CacheContent';
1818
import Column, { FIX_LABEL } from './Column';
1919
import useActive from './useActive';
2020
import useKeyboard from './useKeyboard';
@@ -137,14 +137,21 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
137137
};
138138

139139
// ========================== Option ==========================
140-
const mergedOptions = React.useMemo(() => {
140+
const filteredOptions = React.useMemo(() => {
141141
if (searchValue) {
142142
return searchOptions;
143143
}
144144

145145
return options;
146146
}, [searchValue, searchOptions, options]);
147147

148+
// Update only when open or lockOptions
149+
const mergedOptions = useMemo(
150+
() => filteredOptions,
151+
[open, lockOptions],
152+
(prev, next) => !!next[0] && !next[1],
153+
);
154+
148155
// ========================== Column ==========================
149156
const optionColumns = React.useMemo(() => {
150157
const optionList = [{ options: mergedOptions }];
@@ -248,17 +255,15 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
248255

249256
// >>>>> Render
250257
return (
251-
<CacheContent open={open} lockOptions={lockOptions}>
252-
<div
253-
className={clsx(`${mergedPrefixCls}-menus`, {
254-
[`${mergedPrefixCls}-menu-empty`]: isEmpty,
255-
[`${mergedPrefixCls}-rtl`]: rtl,
256-
})}
257-
ref={containerRef}
258-
>
259-
{columnNodes}
260-
</div>
261-
</CacheContent>
258+
<div
259+
className={clsx(`${mergedPrefixCls}-menus`, {
260+
[`${mergedPrefixCls}-menu-empty`]: isEmpty,
261+
[`${mergedPrefixCls}-rtl`]: rtl,
262+
})}
263+
ref={containerRef}
264+
>
265+
{columnNodes}
266+
</div>
262267
);
263268
});
264269

0 commit comments

Comments
 (0)