@@ -3,6 +3,7 @@ import { clsx } from 'clsx';
33import type { useBaseProps } from '@rc-component/select' ;
44import type { RefOptionListProps } from '@rc-component/select/lib/OptionList' ;
55import * as React from 'react' ;
6+ import useMemo from '@rc-component/util/lib/hooks/useMemo' ;
67import type { DefaultOptionType , LegacyKey , SingleValueType } from '../Cascader' ;
78import CascaderContext from '../context' ;
89import {
@@ -14,7 +15,6 @@ import {
1415 toPathValueStr ,
1516} from '../utils/commonUtil' ;
1617import { toPathOptions } from '../utils/treeUtil' ;
17- import CacheContent from './CacheContent' ;
1818import Column , { FIX_LABEL } from './Column' ;
1919import useActive from './useActive' ;
2020import useKeyboard from './useKeyboard' ;
@@ -29,7 +29,9 @@ export type RawOptionListProps = Pick<
2929 | 'direction'
3030 | 'open'
3131 | 'disabled'
32- > ;
32+ > & {
33+ lockOptions ?: boolean ;
34+ } ;
3335
3436const RawOptionList = React . forwardRef < RefOptionListProps , RawOptionListProps > ( ( props , ref ) => {
3537 const {
@@ -41,6 +43,7 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
4143 direction,
4244 open,
4345 disabled,
46+ lockOptions = false ,
4447 } = props ;
4548
4649 const containerRef = React . useRef < HTMLDivElement > ( null ) ;
@@ -135,14 +138,21 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
135138 } ;
136139
137140 // ========================== Option ==========================
138- const mergedOptions = React . useMemo ( ( ) => {
141+ const filteredOptions = React . useMemo ( ( ) => {
139142 if ( searchValue ) {
140143 return searchOptions ;
141144 }
142145
143146 return options ;
144147 } , [ searchValue , searchOptions , options ] ) ;
145148
149+ // Update only when open or lockOptions
150+ const mergedOptions = useMemo (
151+ ( ) => filteredOptions ,
152+ [ open , lockOptions ] ,
153+ ( prev , next ) => ! ! next [ 0 ] && ! next [ 1 ] ,
154+ ) ;
155+
146156 // ========================== Column ==========================
147157 const optionColumns = React . useMemo ( ( ) => {
148158 const optionList = [ { options : mergedOptions } ] ;
@@ -246,17 +256,15 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
246256
247257 // >>>>> Render
248258 return (
249- < CacheContent open = { open } >
250- < div
251- className = { clsx ( `${ mergedPrefixCls } -menus` , {
252- [ `${ mergedPrefixCls } -menu-empty` ] : isEmpty ,
253- [ `${ mergedPrefixCls } -rtl` ] : rtl ,
254- } ) }
255- ref = { containerRef }
256- >
257- { columnNodes }
258- </ div >
259- </ CacheContent >
259+ < div
260+ className = { clsx ( `${ mergedPrefixCls } -menus` , {
261+ [ `${ mergedPrefixCls } -menu-empty` ] : isEmpty ,
262+ [ `${ mergedPrefixCls } -rtl` ] : rtl ,
263+ } ) }
264+ ref = { containerRef }
265+ >
266+ { columnNodes }
267+ </ div >
260268 ) ;
261269} ) ;
262270
0 commit comments