Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 0 additions & 17 deletions src/OptionList/CacheContent.tsx

This file was deleted.

36 changes: 22 additions & 14 deletions src/OptionList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
Expand All @@ -29,7 +29,9 @@ export type RawOptionListProps = Pick<
| 'direction'
| 'open'
| 'disabled'
>;
> & {
lockOptions?: boolean;
};

const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((props, ref) => {
const {
Expand All @@ -41,6 +43,7 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
direction,
open,
disabled,
lockOptions = false,
} = props;

const containerRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -135,14 +138,21 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
};

// ========================== Option ==========================
const mergedOptions = React.useMemo(() => {
const filteredOptions = React.useMemo(() => {
if (searchValue) {
return searchOptions;
}

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 }];
Expand Down Expand Up @@ -246,17 +256,15 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((

// >>>>> Render
return (
<CacheContent open={open}>
<div
className={clsx(`${mergedPrefixCls}-menus`, {
[`${mergedPrefixCls}-menu-empty`]: isEmpty,
[`${mergedPrefixCls}-rtl`]: rtl,
})}
ref={containerRef}
>
{columnNodes}
</div>
</CacheContent>
<div
className={clsx(`${mergedPrefixCls}-menus`, {
[`${mergedPrefixCls}-menu-empty`]: isEmpty,
[`${mergedPrefixCls}-rtl`]: rtl,
})}
ref={containerRef}
>
{columnNodes}
</div>
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/OptionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as React from 'react';
import RawOptionList from './List';

const RefOptionList = React.forwardRef<RefOptionListProps>((props, ref) => {
const baseProps = useBaseProps();
const { lockOptions, ...baseProps } = useBaseProps();

// >>>>> Render
return <RawOptionList {...props} {...baseProps} ref={ref} />;
return <RawOptionList {...props} {...baseProps} lockOptions={lockOptions} ref={ref} />;
});

export default RefOptionList;
Loading