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 @@ -45,7 +45,7 @@
"dependencies": {
"@rc-component/select": "~1.1.0",
"@rc-component/tree": "~1.0.0",
"@rc-component/util": "^1.2.1",
"@rc-component/util": "^1.3.0",
"classnames": "^2.3.1"
},
"devDependencies": {
Expand Down
14 changes: 5 additions & 9 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseSelect } from '@rc-component/select';
import type { DisplayValueType, Placement } from '@rc-component/select/lib/BaseSelect';
import useId from '@rc-component/util/lib/hooks/useId';
import useEvent from '@rc-component/util/lib/hooks/useEvent';
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
import * as React from 'react';
import CascaderContext from './context';
import useDisplayValues from './hooks/useDisplayValues';
Expand Down Expand Up @@ -250,10 +250,8 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
const multiple = !!checkable;

// =========================== Values ===========================
const [rawValues, setRawValues] = useMergedState<
InternalValueType | undefined,
SingleValueType[]
>(defaultValue, { value, postState: toRawValues });
const [interanlRawValues, setRawValues] = useControlledState(defaultValue, value);
const rawValues = toRawValues(interanlRawValues);

// ========================= FieldNames =========================
const mergedFieldNames = React.useMemo(
Expand All @@ -272,10 +270,8 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
// =========================== Search ===========================
const [mergedShowSearch, searchConfig] = useSearchConfig(showSearch, props);
const { autoClearSearchValue = true, searchValue, onSearch } = searchConfig;
const [mergedSearchValue, setSearchValue] = useMergedState('', {
value: searchValue,
postState: search => search || '',
});
const [internalSearchValue, setSearchValue] = useControlledState('', searchValue);
const mergedSearchValue = internalSearchValue || '';

const onInternalSearch: BaseSelectProps['onSearch'] = (searchText, info) => {
setSearchValue(searchText);
Expand Down
10 changes: 4 additions & 6 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { useEvent, useMergedState } from '@rc-component/util';
import { useEvent, useControlledState } from '@rc-component/util';
import * as React from 'react';
import type {
CascaderProps,
Expand Down Expand Up @@ -78,10 +78,8 @@ export default function Panel<
const multiple = !!checkable;

// ========================= Values =========================
const [rawValues, setRawValues] = useMergedState<
InternalValueType | undefined,
SingleValueType[]
>(defaultValue, { value, postState: toRawValues });
const [interanlRawValues, setRawValues] = useControlledState(defaultValue, value);
const rawValues = toRawValues(interanlRawValues);

// ========================= FieldNames =========================
const mergedFieldNames = React.useMemo(
Expand Down Expand Up @@ -161,7 +159,7 @@ export default function Panel<
expandIcon,
loadingIcon,
popupMenuColumnStyle: undefined,
optionRender
optionRender,
}),
[
mergedOptions,
Expand Down
Loading