From 83b315e2f74fd4fcfd8b56ef72e0d4da192e886f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 27 Jan 2026 16:18:38 +0800 Subject: [PATCH 1/3] fix: Cache option for filter --- package.json | 2 +- src/OptionList/CacheContent.tsx | 3 ++- src/OptionList/List.tsx | 4 +++- src/OptionList/index.tsx | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 61150e62..6aeac86b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "test": "rc-test" }, "dependencies": { - "@rc-component/select": "~1.5.0", + "@rc-component/select": "~1.5.2", "@rc-component/tree": "~1.2.0", "@rc-component/util": "^1.4.0", "clsx": "^2.1.1" diff --git a/src/OptionList/CacheContent.tsx b/src/OptionList/CacheContent.tsx index 4f2ec10c..06edf310 100644 --- a/src/OptionList/CacheContent.tsx +++ b/src/OptionList/CacheContent.tsx @@ -3,11 +3,12 @@ import * as React from 'react'; export interface CacheContentProps { children?: React.ReactNode; open?: boolean; + lockOptions?: boolean; } const CacheContent = React.memo( ({ children }: CacheContentProps) => children as React.ReactElement, - (_, next) => !next.open, + (_, next) => !next.open && next.lockOptions, ); if (process.env.NODE_ENV !== 'production') { diff --git a/src/OptionList/List.tsx b/src/OptionList/List.tsx index bb01a3f9..b70c0a8d 100644 --- a/src/OptionList/List.tsx +++ b/src/OptionList/List.tsx @@ -29,6 +29,7 @@ export type RawOptionListProps = Pick< | 'direction' | 'open' | 'disabled' + | 'lockOptions' >; const RawOptionList = React.forwardRef((props, ref) => { @@ -41,6 +42,7 @@ const RawOptionList = React.forwardRef(( direction, open, disabled, + lockOptions, } = props; const containerRef = React.useRef(null); @@ -246,7 +248,7 @@ const RawOptionList = React.forwardRef(( // >>>>> Render return ( - +
((props, ref) => { - const baseProps = useBaseProps(); + const { lockOptions, ...baseProps } = useBaseProps(); // >>>>> Render - return ; + return ; }); export default RefOptionList; From 91bb98a950c756b382096b25cacdf276fcfd03f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 27 Jan 2026 16:37:26 +0800 Subject: [PATCH 2/3] chore: fix logic --- src/OptionList/CacheContent.tsx | 18 ------------------ src/OptionList/List.tsx | 31 ++++++++++++++++++------------- 2 files changed, 18 insertions(+), 31 deletions(-) delete mode 100644 src/OptionList/CacheContent.tsx diff --git a/src/OptionList/CacheContent.tsx b/src/OptionList/CacheContent.tsx deleted file mode 100644 index 06edf310..00000000 --- a/src/OptionList/CacheContent.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import * as React from 'react'; - -export interface CacheContentProps { - children?: React.ReactNode; - open?: boolean; - lockOptions?: boolean; -} - -const CacheContent = React.memo( - ({ children }: CacheContentProps) => children as React.ReactElement, - (_, next) => !next.open && next.lockOptions, -); - -if (process.env.NODE_ENV !== 'production') { - CacheContent.displayName = 'CacheContent'; -} - -export default CacheContent; diff --git a/src/OptionList/List.tsx b/src/OptionList/List.tsx index b70c0a8d..9e588b82 100644 --- a/src/OptionList/List.tsx +++ b/src/OptionList/List.tsx @@ -3,6 +3,7 @@ import { clsx } from 'clsx'; import type { useBaseProps } from '@rc-component/select'; import type { RefOptionListProps } from '@rc-component/select/lib/OptionList'; import * as React from 'react'; +import useMemo from '@rc-component/util/lib/hooks/useMemo'; import type { DefaultOptionType, LegacyKey, SingleValueType } from '../Cascader'; import CascaderContext from '../context'; import { @@ -14,7 +15,6 @@ import { toPathValueStr, } from '../utils/commonUtil'; import { toPathOptions } from '../utils/treeUtil'; -import CacheContent from './CacheContent'; import Column, { FIX_LABEL } from './Column'; import useActive from './useActive'; import useKeyboard from './useKeyboard'; @@ -137,7 +137,7 @@ const RawOptionList = React.forwardRef(( }; // ========================== Option ========================== - const mergedOptions = React.useMemo(() => { + const filteredOptions = React.useMemo(() => { if (searchValue) { return searchOptions; } @@ -145,6 +145,13 @@ const RawOptionList = React.forwardRef(( return options; }, [searchValue, searchOptions, options]); + // Update only when open or lockOptions + const mergedOptions = useMemo( + () => filteredOptions, + [open, lockOptions], + (prev, next) => !!next[0] && !next[1], + ); + // ========================== Column ========================== const optionColumns = React.useMemo(() => { const optionList = [{ options: mergedOptions }]; @@ -248,17 +255,15 @@ const RawOptionList = React.forwardRef(( // >>>>> Render return ( - -
- {columnNodes} -
-
+
+ {columnNodes} +
); }); From 2654066015e5b607bc1c331bfe7b644795af03e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 27 Jan 2026 16:40:48 +0800 Subject: [PATCH 3/3] chore: fix ts --- src/OptionList/List.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OptionList/List.tsx b/src/OptionList/List.tsx index 9e588b82..c99ef264 100644 --- a/src/OptionList/List.tsx +++ b/src/OptionList/List.tsx @@ -29,8 +29,9 @@ export type RawOptionListProps = Pick< | 'direction' | 'open' | 'disabled' - | 'lockOptions' ->; +> & { + lockOptions?: boolean; +}; const RawOptionList = React.forwardRef((props, ref) => { const { @@ -42,7 +43,7 @@ const RawOptionList = React.forwardRef(( direction, open, disabled, - lockOptions, + lockOptions = false, } = props; const containerRef = React.useRef(null);