Skip to content

Commit f16c2a8

Browse files
authored
feat: retire deprecated api and rename to popup (#558)
* refactor: update prop names and remove deprecated props * chore: adjust logic * chore: remove useless code * refactor: rename to popup * chore: change import path * chore: remove useless test case * chore: remove compatible logic * revert * revert * refactor: update key logic * fix: type error
1 parent ee97a7d commit f16c2a8

22 files changed

+109
-146
lines changed

docs/demo/dropdown-render.md

-8
This file was deleted.

docs/demo/popup-render.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: popup-render
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../../examples/popup-render.tsx"></code>

examples/dropdown-render.tsx examples/popup-render.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const Demo = () => {
7474
<div>
7575
{menus}
7676
<hr />
77-
Hey, DropdownRender, Long DropdownRender, Long DropdownRender
77+
Hey, popupRender, Long popupRender, Long popupRender
7878
</div>
7979
)}
8080
>

examples/visible.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const addressOptions = [
5959

6060
const Demo = () => {
6161
const [value, setValue] = useState<string[]>([]);
62-
const [popupVisible, setPopupVisible] = useState(false);
62+
const [open, setOpen] = useState(false);
6363

6464
const getLabel = () => {
6565
return arrayTreeFilter(addressOptions, (o, level) => o.value === value[level])
@@ -69,10 +69,10 @@ const Demo = () => {
6969

7070
return (
7171
<Cascader
72-
popupVisible={popupVisible}
72+
open={open}
7373
value={value}
7474
options={addressOptions}
75-
onPopupVisibleChange={open => setPopupVisible(open)}
75+
onPopupVisibleChange={open => setOpen(open)}
7676
onChange={value => setValue(value)}
7777
>
7878
<input value={getLabel()} readOnly />

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"build": "dumi build",
3434
"compile": "father build",
3535
"coverage": "father test --coverage",
36+
"tsc": "bunx tsc --noEmit",
3637
"deploy": "UMI_ENV=gh npm run build && gh-pages -d dist",
3738
"lint": "eslint src/ examples/ --ext .tsx,.ts,.jsx,.jsx",
3839
"now-build": "npm run build",
@@ -43,9 +44,9 @@
4344
},
4445
"dependencies": {
4546
"@rc-component/select": "~1.0.0",
47+
"@rc-component/tree": "~1.0.0",
4648
"@rc-component/util": "^1.2.1",
47-
"classnames": "^2.3.1",
48-
"rc-tree": "~5.13.1"
49+
"classnames": "^2.3.1"
4950
},
5051
"devDependencies": {
5152
"@rc-component/father-plugin": "^2.0.2",
@@ -55,8 +56,8 @@
5556
"@types/classnames": "^2.2.6",
5657
"@types/enzyme": "^3.1.15",
5758
"@types/jest": "^29.4.0",
58-
"@types/react": "^17.0.38",
59-
"@types/react-dom": "^18.0.11",
59+
"@types/react": "^19.0.0",
60+
"@types/react-dom": "^19.0.0",
6061
"@types/warning": "^3.0.0",
6162
"@umijs/fabric": "^4.0.0",
6263
"array-tree-filter": "^3.0.2",

src/Cascader.tsx

+25-36
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
toRawValues,
2929
} from './utils/commonUtil';
3030
import { formatStrategyValues, toPathOptions } from './utils/treeUtil';
31-
import warningProps, { warningNullOptions } from './utils/warningPropsUtil';
31+
import { warningNullOptions } from './utils/warningPropsUtil';
3232

3333
export interface BaseOptionType {
3434
disabled?: boolean;
@@ -71,9 +71,9 @@ interface BaseCascaderProps<
7171
OptionType extends DefaultOptionType = DefaultOptionType,
7272
ValueField extends keyof OptionType = keyof OptionType,
7373
> extends Omit<
74-
BaseSelectPropsWithoutPrivate,
75-
'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch'
76-
> {
74+
BaseSelectPropsWithoutPrivate,
75+
'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch'
76+
> {
7777
// MISC
7878
id?: string;
7979
prefixCls?: string;
@@ -99,18 +99,12 @@ interface BaseCascaderProps<
9999
// Options
100100
options?: OptionType[];
101101
/** @private Internal usage. Do not use in your production. */
102-
dropdownPrefixCls?: string;
102+
popupPrefixCls?: string;
103103
loadData?: (selectOptions: OptionType[]) => void;
104104

105-
// Open
106-
/** @deprecated Use `open` instead */
107-
popupVisible?: boolean;
108-
109105
popupClassName?: string;
110-
dropdownMenuColumnStyle?: React.CSSProperties;
106+
popupMenuColumnStyle?: React.CSSProperties;
111107

112-
/** @deprecated Use `placement` instead */
113-
popupPlacement?: Placement;
114108
placement?: Placement;
115109
builtinPlacements?: BuildInPlacements;
116110

@@ -135,8 +129,8 @@ export type ValueType<
135129
ValueField extends keyof OptionType = keyof OptionType,
136130
> = keyof OptionType extends ValueField
137131
? unknown extends OptionType['value']
138-
? OptionType[ValueField]
139-
: OptionType['value']
132+
? OptionType[ValueField]
133+
: OptionType['value']
140134
: OptionType[ValueField];
141135

142136
export type GetValueType<
@@ -167,6 +161,9 @@ export interface CascaderProps<
167161
}
168162

169163
export type SingleValueType = (string | number)[];
164+
165+
export type LegacyKey = string | number;
166+
170167
export type InternalValueType = SingleValueType | SingleValueType[];
171168

172169
export interface InternalFieldNames extends Required<FieldNames> {
@@ -210,18 +207,15 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
210207

211208
// Options
212209
options,
213-
dropdownPrefixCls,
210+
popupPrefixCls,
214211
loadData,
215212

216-
// Open
217-
popupVisible,
218213
open,
219214

220215
popupClassName,
221-
dropdownMenuColumnStyle,
216+
popupMenuColumnStyle,
222217
popupStyle: customPopupStyle,
223218

224-
popupPlacement,
225219
placement,
226220

227221
onPopupVisibleChange,
@@ -281,7 +275,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
281275
mergedSearchValue,
282276
mergedOptions,
283277
mergedFieldNames,
284-
dropdownPrefixCls || prefixCls,
278+
popupPrefixCls || prefixCls,
285279
searchConfig,
286280
changeOnSelect || multiple,
287281
);
@@ -374,18 +368,13 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
374368
onInternalSelect(valueCells);
375369
};
376370

377-
// ============================ Open ============================
378-
const mergedOpen = open !== undefined ? open : popupVisible;
379-
380-
const mergedPlacement = placement || popupPlacement;
381-
382371
const onInternalPopupVisibleChange = (nextVisible: boolean) => {
383372
onPopupVisibleChange?.(nextVisible);
384373
};
385374

375+
386376
// ========================== Warning ===========================
387377
if (process.env.NODE_ENV !== 'production') {
388-
warningProps(props);
389378
warningNullOptions(mergedOptions, mergedFieldNames);
390379
}
391380

@@ -400,12 +389,12 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
400389
onSelect: onInternalSelect,
401390
checkable,
402391
searchOptions,
403-
dropdownPrefixCls,
392+
popupPrefixCls,
404393
loadData,
405394
expandTrigger,
406395
expandIcon,
407396
loadingIcon,
408-
dropdownMenuColumnStyle,
397+
popupMenuColumnStyle,
409398
optionRender,
410399
}),
411400
[
@@ -417,12 +406,12 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
417406
onInternalSelect,
418407
checkable,
419408
searchOptions,
420-
dropdownPrefixCls,
409+
popupPrefixCls,
421410
loadData,
422411
expandTrigger,
423412
expandIcon,
424413
loadingIcon,
425-
dropdownMenuColumnStyle,
414+
popupMenuColumnStyle,
426415
optionRender,
427416
],
428417
);
@@ -435,12 +424,12 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
435424
const popupStyle: React.CSSProperties =
436425
// Search to match width
437426
(mergedSearchValue && searchConfig.matchInputWidth) ||
438-
// Empty keep the width
439-
emptyOptions
427+
// Empty keep the width
428+
emptyOptions
440429
? {}
441430
: {
442-
minWidth: 'auto',
443-
};
431+
minWidth: 'auto',
432+
};
444433

445434
return (
446435
<CascaderContext.Provider value={cascaderContext}>
@@ -468,9 +457,9 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re
468457
OptionList={OptionList}
469458
emptyOptions={emptyOptions}
470459
// Open
471-
open={mergedOpen}
460+
open={open}
472461
popupClassName={popupClassName}
473-
placement={mergedPlacement}
462+
placement={placement}
474463
onPopupVisibleChange={onInternalPopupVisibleChange}
475464
// Children
476465
getRawInputElement={() => children as React.ReactElement}

src/OptionList/Column.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
5050
expandTrigger,
5151
expandIcon,
5252
loadingIcon,
53-
dropdownMenuColumnStyle,
53+
popupMenuColumnStyle,
5454
optionRender,
5555
} = React.useContext(CascaderContext);
5656

@@ -155,7 +155,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
155155
[`${menuItemPrefixCls}-disabled`]: isOptionDisabled(disabled),
156156
[`${menuItemPrefixCls}-loading`]: isLoading,
157157
})}
158-
style={dropdownMenuColumnStyle}
158+
style={popupMenuColumnStyle}
159159
role="menuitemcheckbox"
160160
title={title}
161161
aria-checked={checked}

src/OptionList/List.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import classNames from 'classnames';
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 type { DefaultOptionType, SingleValueType } from '../Cascader';
6+
import type { DefaultOptionType, LegacyKey, SingleValueType } from '../Cascader';
77
import CascaderContext from '../context';
88
import {
99
getFullPathKeys,
@@ -54,17 +54,17 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
5454
changeOnSelect,
5555
onSelect,
5656
searchOptions,
57-
dropdownPrefixCls,
57+
popupPrefixCls,
5858
loadData,
5959
expandTrigger,
6060
} = React.useContext(CascaderContext);
6161

62-
const mergedPrefixCls = dropdownPrefixCls || prefixCls;
62+
const mergedPrefixCls = popupPrefixCls || prefixCls;
6363

6464
// ========================= loadData =========================
65-
const [loadingKeys, setLoadingKeys] = React.useState<React.Key[]>([]);
65+
const [loadingKeys, setLoadingKeys] = React.useState<LegacyKey[]>([]);
6666

67-
const internalLoadData = (valueCells: React.Key[]) => {
67+
const internalLoadData = (valueCells: LegacyKey[]) => {
6868
// Do not load when search
6969
if (!loadData || searchValue) {
7070
return;
@@ -108,7 +108,7 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
108108
const [activeValueCells, setActiveValueCells] = useActive(multiple, open);
109109

110110
// =========================== Path ===========================
111-
const onPathOpen = (nextValueCells: React.Key[]) => {
111+
const onPathOpen = (nextValueCells: LegacyKey[]) => {
112112
setActiveValueCells(nextValueCells);
113113

114114
// Trigger loadData

src/OptionList/useActive.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import * as React from 'react';
22
import CascaderContext from '../context';
3+
import { LegacyKey } from '@/Cascader';
34

45
/**
56
* Control the active open options path.
67
*/
78
const useActive = (
89
multiple?: boolean,
910
open?: boolean,
10-
): [React.Key[], (activeValueCells: React.Key[]) => void] => {
11+
): [LegacyKey[], (activeValueCells: LegacyKey[]) => void] => {
1112
const { values } = React.useContext(CascaderContext);
1213

1314
const firstValueCells = values[0];
1415

1516
// Record current dropdown active options
1617
// This also control the open status
17-
const [activeValueCells, setActiveValueCells] = React.useState<React.Key[]>([]);
18+
const [activeValueCells, setActiveValueCells] = React.useState<LegacyKey[]>([]);
1819

1920
React.useEffect(
2021
() => {

src/OptionList/useKeyboard.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
22
import KeyCode from '@rc-component/util/lib/KeyCode';
33
import * as React from 'react';
4-
import type { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
4+
import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
55
import { SEARCH_MARK } from '../hooks/useSearchOptions';
66
import { getFullPathKeys, toPathKey } from '../utils/commonUtil';
77

88
export default (
99
ref: React.Ref<RefOptionListProps>,
1010
options: DefaultOptionType[],
1111
fieldNames: InternalFieldNames,
12-
activeValueCells: React.Key[],
13-
setActiveValueCells: (activeValueCells: React.Key[]) => void,
12+
activeValueCells: LegacyKey[],
13+
setActiveValueCells: (activeValueCells: LegacyKey[]) => void,
1414
onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void,
1515
contextProps: {
1616
direction?: 'ltr' | 'rtl';
@@ -28,7 +28,7 @@ export default (
2828
let currentOptions = options;
2929

3030
const mergedActiveIndexes: number[] = [];
31-
const mergedActiveValueCells: React.Key[] = [];
31+
const mergedActiveValueCells: LegacyKey[] = [];
3232

3333
const len = activeValueCells.length;
3434

@@ -64,7 +64,7 @@ export default (
6464
}, [activeValueCells, fieldNames, options]);
6565

6666
// Update active value cells and scroll to target element
67-
const internalSetActiveValueCells = (next: React.Key[]) => {
67+
const internalSetActiveValueCells = (next: LegacyKey[]) => {
6868
setActiveValueCells(next);
6969
};
7070

src/Panel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ export default function Panel<
153153
onSelect: onInternalSelect,
154154
checkable,
155155
searchOptions: [],
156-
dropdownPrefixCls: undefined,
156+
popupPrefixCls: undefined,
157157
loadData,
158158
expandTrigger,
159159
expandIcon,
160160
loadingIcon,
161-
dropdownMenuColumnStyle: undefined,
161+
popupMenuColumnStyle: undefined,
162162
}),
163163
[
164164
mergedOptions,

0 commit comments

Comments
 (0)