@rc-component/cascader 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/es/Cascader.d.ts +3 -6
  2. package/es/Cascader.js +9 -17
  3. package/es/OptionList/CacheContent.d.ts +1 -1
  4. package/es/OptionList/Column.js +16 -2
  5. package/es/OptionList/List.js +2 -2
  6. package/es/OptionList/useActive.d.ts +2 -2
  7. package/es/OptionList/useActive.js +0 -1
  8. package/es/OptionList/useKeyboard.d.ts +2 -2
  9. package/es/Panel.js +2 -2
  10. package/es/context.d.ts +2 -2
  11. package/es/hooks/useEntities.d.ts +1 -1
  12. package/es/hooks/useEntities.js +1 -1
  13. package/es/hooks/useOptions.d.ts +2 -3
  14. package/es/hooks/useSelect.d.ts +2 -3
  15. package/es/hooks/useSelect.js +1 -1
  16. package/es/hooks/useValues.d.ts +3 -4
  17. package/es/hooks/useValues.js +1 -1
  18. package/es/utils/treeUtil.d.ts +2 -3
  19. package/es/utils/warningPropsUtil.d.ts +1 -3
  20. package/es/utils/warningPropsUtil.js +1 -11
  21. package/lib/Cascader.d.ts +3 -6
  22. package/lib/Cascader.js +9 -17
  23. package/lib/OptionList/CacheContent.d.ts +1 -1
  24. package/lib/OptionList/Column.js +16 -2
  25. package/lib/OptionList/List.js +2 -2
  26. package/lib/OptionList/useActive.d.ts +2 -2
  27. package/lib/OptionList/useKeyboard.d.ts +2 -2
  28. package/lib/Panel.js +2 -2
  29. package/lib/context.d.ts +2 -2
  30. package/lib/hooks/useEntities.d.ts +1 -1
  31. package/lib/hooks/useEntities.js +1 -1
  32. package/lib/hooks/useOptions.d.ts +2 -3
  33. package/lib/hooks/useSelect.d.ts +2 -3
  34. package/lib/hooks/useSelect.js +1 -1
  35. package/lib/hooks/useValues.d.ts +3 -4
  36. package/lib/hooks/useValues.js +1 -1
  37. package/lib/utils/treeUtil.d.ts +2 -3
  38. package/lib/utils/warningPropsUtil.d.ts +1 -3
  39. package/lib/utils/warningPropsUtil.js +1 -12
  40. package/package.json +6 -5
package/es/Cascader.d.ts CHANGED
@@ -37,14 +37,10 @@ interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOption
37
37
  expandTrigger?: 'hover' | 'click';
38
38
  options?: OptionType[];
39
39
  /** @private Internal usage. Do not use in your production. */
40
- dropdownPrefixCls?: string;
40
+ popupPrefixCls?: string;
41
41
  loadData?: (selectOptions: OptionType[]) => void;
42
- /** @deprecated Use `open` instead */
43
- popupVisible?: boolean;
44
42
  popupClassName?: string;
45
- dropdownMenuColumnStyle?: React.CSSProperties;
46
- /** @deprecated Use `placement` instead */
47
- popupPlacement?: Placement;
43
+ popupMenuColumnStyle?: React.CSSProperties;
48
44
  placement?: Placement;
49
45
  builtinPlacements?: BuildInPlacements;
50
46
  onPopupVisibleChange?: (open: boolean) => void;
@@ -66,6 +62,7 @@ export interface CascaderProps<OptionType extends DefaultOptionType = DefaultOpt
66
62
  onChange?: (value: GetValueType<OptionType, ValueField, Multiple>, selectOptions: GetOptionType<OptionType, Multiple>) => void;
67
63
  }
68
64
  export type SingleValueType = (string | number)[];
65
+ export type LegacyKey = string | number;
69
66
  export type InternalValueType = SingleValueType | SingleValueType[];
70
67
  export interface InternalFieldNames extends Required<FieldNames> {
71
68
  key: string;
package/es/Cascader.js CHANGED
@@ -16,7 +16,7 @@ import OptionList from "./OptionList";
16
16
  import Panel from "./Panel";
17
17
  import { fillFieldNames, SHOW_CHILD, SHOW_PARENT, toPathKeys, toRawValues } from "./utils/commonUtil";
18
18
  import { formatStrategyValues, toPathOptions } from "./utils/treeUtil";
19
- import warningProps, { warningNullOptions } from "./utils/warningPropsUtil";
19
+ import { warningNullOptions } from "./utils/warningPropsUtil";
20
20
  const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
21
21
  const {
22
22
  // MISC
@@ -39,15 +39,12 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
39
39
  expandTrigger,
40
40
  // Options
41
41
  options,
42
- dropdownPrefixCls,
42
+ popupPrefixCls,
43
43
  loadData,
44
- // Open
45
- popupVisible,
46
44
  open,
47
45
  popupClassName,
48
- dropdownMenuColumnStyle,
46
+ popupMenuColumnStyle,
49
47
  popupStyle: customPopupStyle,
50
- popupPlacement,
51
48
  placement,
52
49
  onPopupVisibleChange,
53
50
  // Icon
@@ -89,7 +86,7 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
89
86
  }
90
87
  };
91
88
  const [mergedShowSearch, searchConfig] = useSearchConfig(showSearch);
92
- const searchOptions = useSearchOptions(mergedSearchValue, mergedOptions, mergedFieldNames, dropdownPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
89
+ const searchOptions = useSearchOptions(mergedSearchValue, mergedOptions, mergedFieldNames, popupPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
93
90
 
94
91
  // =========================== Values ===========================
95
92
  const getMissingValues = useMissingValues(mergedOptions, mergedFieldNames);
@@ -139,17 +136,12 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
139
136
  } = info.values[0];
140
137
  onInternalSelect(valueCells);
141
138
  };
142
-
143
- // ============================ Open ============================
144
- const mergedOpen = open !== undefined ? open : popupVisible;
145
- const mergedPlacement = placement || popupPlacement;
146
139
  const onInternalPopupVisibleChange = nextVisible => {
147
140
  onPopupVisibleChange?.(nextVisible);
148
141
  };
149
142
 
150
143
  // ========================== Warning ===========================
151
144
  if (process.env.NODE_ENV !== 'production') {
152
- warningProps(props);
153
145
  warningNullOptions(mergedOptions, mergedFieldNames);
154
146
  }
155
147
 
@@ -163,14 +155,14 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
163
155
  onSelect: onInternalSelect,
164
156
  checkable,
165
157
  searchOptions,
166
- dropdownPrefixCls,
158
+ popupPrefixCls,
167
159
  loadData,
168
160
  expandTrigger,
169
161
  expandIcon,
170
162
  loadingIcon,
171
- dropdownMenuColumnStyle,
163
+ popupMenuColumnStyle,
172
164
  optionRender
173
- }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, dropdownPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, dropdownMenuColumnStyle, optionRender]);
165
+ }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, popupPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, popupMenuColumnStyle, optionRender]);
174
166
 
175
167
  // ==============================================================
176
168
  // == Render ==
@@ -212,9 +204,9 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
212
204
  emptyOptions: emptyOptions
213
205
  // Open
214
206
  ,
215
- open: mergedOpen,
207
+ open: open,
216
208
  popupClassName: popupClassName,
217
- placement: mergedPlacement,
209
+ placement: placement,
218
210
  onPopupVisibleChange: onInternalPopupVisibleChange
219
211
  // Children
220
212
  ,
@@ -3,5 +3,5 @@ export interface CacheContentProps {
3
3
  children?: React.ReactNode;
4
4
  open?: boolean;
5
5
  }
6
- declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
6
+ declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>;
7
7
  export default CacheContent;
@@ -22,13 +22,14 @@ export default function Column({
22
22
  }) {
23
23
  const menuPrefixCls = `${prefixCls}-menu`;
24
24
  const menuItemPrefixCls = `${prefixCls}-menu-item`;
25
+ const menuRef = React.useRef(null);
25
26
  const {
26
27
  fieldNames,
27
28
  changeOnSelect,
28
29
  expandTrigger,
29
30
  expandIcon,
30
31
  loadingIcon,
31
- dropdownMenuColumnStyle,
32
+ popupMenuColumnStyle,
32
33
  optionRender
33
34
  } = React.useContext(CascaderContext);
34
35
  const hoverOpen = expandTrigger === 'hover';
@@ -69,10 +70,23 @@ export default function Column({
69
70
  fullPathKey
70
71
  };
71
72
  }), [options, checkedSet, fieldNames, halfCheckedSet, loadingKeys, prevValuePath]);
73
+ React.useEffect(() => {
74
+ if (menuRef.current) {
75
+ const selector = `.${menuItemPrefixCls}-active`;
76
+ const activeElement = menuRef.current.querySelector(selector);
77
+ if (activeElement) {
78
+ activeElement.scrollIntoView({
79
+ block: 'nearest',
80
+ inline: 'nearest'
81
+ });
82
+ }
83
+ }
84
+ }, [activeValue, menuItemPrefixCls]);
72
85
 
73
86
  // ============================ Render ============================
74
87
  return /*#__PURE__*/React.createElement("ul", {
75
88
  className: menuPrefixCls,
89
+ ref: menuRef,
76
90
  role: "menu"
77
91
  }, optionInfoList.map(({
78
92
  disabled,
@@ -123,7 +137,7 @@ export default function Column({
123
137
  [`${menuItemPrefixCls}-disabled`]: isOptionDisabled(disabled),
124
138
  [`${menuItemPrefixCls}-loading`]: isLoading
125
139
  }),
126
- style: dropdownMenuColumnStyle,
140
+ style: popupMenuColumnStyle,
127
141
  role: "menuitemcheckbox",
128
142
  title: title,
129
143
  "aria-checked": checked,
@@ -30,11 +30,11 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
30
30
  changeOnSelect,
31
31
  onSelect,
32
32
  searchOptions,
33
- dropdownPrefixCls,
33
+ popupPrefixCls,
34
34
  loadData,
35
35
  expandTrigger
36
36
  } = React.useContext(CascaderContext);
37
- const mergedPrefixCls = dropdownPrefixCls || prefixCls;
37
+ const mergedPrefixCls = popupPrefixCls || prefixCls;
38
38
 
39
39
  // ========================= loadData =========================
40
40
  const [loadingKeys, setLoadingKeys] = React.useState([]);
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
1
+ import { LegacyKey } from "../Cascader";
2
2
  /**
3
3
  * Control the active open options path.
4
4
  */
5
- declare const useActive: (multiple?: boolean, open?: boolean) => [React.Key[], (activeValueCells: React.Key[]) => void];
5
+ declare const useActive: (multiple?: boolean, open?: boolean) => [LegacyKey[], (activeValueCells: LegacyKey[]) => void];
6
6
  export default useActive;
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import CascaderContext from "../context";
3
-
4
3
  /**
5
4
  * Control the active open options path.
6
5
  */
@@ -1,7 +1,7 @@
1
1
  import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
- import type { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
4
- declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: React.Key[], setActiveValueCells: (activeValueCells: React.Key[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
3
+ import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
+ declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: LegacyKey[], setActiveValueCells: (activeValueCells: LegacyKey[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
5
5
  direction?: "ltr" | "rtl" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
package/es/Panel.js CHANGED
@@ -85,12 +85,12 @@ export default function Panel(props) {
85
85
  onSelect: onInternalSelect,
86
86
  checkable,
87
87
  searchOptions: [],
88
- dropdownPrefixCls: undefined,
88
+ popupPrefixCls: undefined,
89
89
  loadData,
90
90
  expandTrigger,
91
91
  expandIcon,
92
92
  loadingIcon,
93
- dropdownMenuColumnStyle: undefined
93
+ popupMenuColumnStyle: undefined
94
94
  }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, loadData, expandTrigger, expandIcon, loadingIcon]);
95
95
 
96
96
  // ========================= Render =========================
package/es/context.d.ts CHANGED
@@ -9,12 +9,12 @@ export interface CascaderContextProps {
9
9
  onSelect: (valuePath: SingleValueType) => void;
10
10
  checkable?: boolean | React.ReactNode;
11
11
  searchOptions: DefaultOptionType[];
12
- dropdownPrefixCls?: string;
12
+ popupPrefixCls?: string;
13
13
  loadData?: (selectOptions: DefaultOptionType[]) => void;
14
14
  expandTrigger?: 'hover' | 'click';
15
15
  expandIcon?: React.ReactNode;
16
16
  loadingIcon?: React.ReactNode;
17
- dropdownMenuColumnStyle?: React.CSSProperties;
17
+ popupMenuColumnStyle?: React.CSSProperties;
18
18
  optionRender?: CascaderProps['optionRender'];
19
19
  }
20
20
  declare const CascaderContext: React.Context<CascaderContextProps>;
@@ -1,5 +1,5 @@
1
1
  import type { DefaultOptionType, InternalFieldNames } from '../Cascader';
2
- import type { DataEntity } from 'rc-tree/lib/interface';
2
+ import type { DataEntity } from '@rc-component/tree/lib/interface';
3
3
  export interface OptionsInfo {
4
4
  keyEntities: Record<string, DataEntity>;
5
5
  pathKeyEntities: Record<string, DataEntity>;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { convertDataToEntities } from "rc-tree/es/utils/treeUtil";
2
+ import { convertDataToEntities } from "@rc-component/tree/es/utils/treeUtil";
3
3
  import { VALUE_SPLIT } from "../utils/commonUtil";
4
4
  /** Lazy parse options data into conduct-able info to avoid perf issue in single mode */
5
5
  export default ((options, fieldNames) => {
@@ -1,9 +1,8 @@
1
- import * as React from 'react';
2
1
  import type { DefaultOptionType } from '..';
3
- import type { InternalFieldNames, SingleValueType } from '../Cascader';
2
+ import type { InternalFieldNames, SingleValueType, LegacyKey } from '../Cascader';
4
3
  import { type GetEntities } from './useEntities';
5
4
  export default function useOptions(mergedFieldNames: InternalFieldNames, options?: DefaultOptionType[]): [
6
5
  mergedOptions: DefaultOptionType[],
7
6
  getPathKeyEntities: GetEntities,
8
- getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[]
7
+ getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[]
9
8
  ];
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
- import type { InternalValueType, ShowCheckedStrategy, SingleValueType } from '../Cascader';
1
+ import type { InternalValueType, LegacyKey, ShowCheckedStrategy, SingleValueType } from '../Cascader';
3
2
  import type { GetEntities } from './useEntities';
4
- export default function useSelect(multiple: boolean, triggerChange: (nextValues: InternalValueType) => void, checkedValues: SingleValueType[], halfCheckedValues: SingleValueType[], missingCheckedValues: SingleValueType[], getPathKeyEntities: GetEntities, getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[], showCheckedStrategy?: ShowCheckedStrategy): (valuePath: SingleValueType) => void;
3
+ export default function useSelect(multiple: boolean, triggerChange: (nextValues: InternalValueType) => void, checkedValues: SingleValueType[], halfCheckedValues: SingleValueType[], missingCheckedValues: SingleValueType[], getPathKeyEntities: GetEntities, getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[], showCheckedStrategy?: ShowCheckedStrategy): (valuePath: SingleValueType) => void;
@@ -1,4 +1,4 @@
1
- import { conductCheck } from "rc-tree/es/utils/conductUtil";
1
+ import { conductCheck } from "@rc-component/tree/es/utils/conductUtil";
2
2
  import { toPathKey, toPathKeys } from "../utils/commonUtil";
3
3
  import { formatStrategyValues } from "../utils/treeUtil";
4
4
  export default function useSelect(multiple, triggerChange, checkedValues, halfCheckedValues, missingCheckedValues, getPathKeyEntities, getValueByKeyPath, showCheckedStrategy) {
@@ -1,8 +1,7 @@
1
- import type { DataEntity } from 'rc-tree/lib/interface';
2
- import * as React from 'react';
3
- import type { SingleValueType } from '../Cascader';
1
+ import type { DataEntity } from '@rc-component/tree/lib/interface';
2
+ import type { LegacyKey, SingleValueType } from '../Cascader';
4
3
  import type { GetMissValues } from './useMissingValues';
5
- export default function useValues(multiple: boolean, rawValues: SingleValueType[], getPathKeyEntities: () => Record<string, DataEntity>, getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[], getMissingValues: GetMissValues): [
4
+ export default function useValues(multiple: boolean, rawValues: SingleValueType[], getPathKeyEntities: () => Record<string, DataEntity>, getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[], getMissingValues: GetMissValues): [
6
5
  checkedValues: SingleValueType[],
7
6
  halfCheckedValues: SingleValueType[],
8
7
  missingCheckedValues: SingleValueType[]
@@ -1,4 +1,4 @@
1
- import { conductCheck } from "rc-tree/es/utils/conductUtil";
1
+ import { conductCheck } from "@rc-component/tree/es/utils/conductUtil";
2
2
  import * as React from 'react';
3
3
  import { toPathKeys } from "../utils/commonUtil";
4
4
  export default function useValues(multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues) {
@@ -1,7 +1,6 @@
1
- /// <reference types="react" />
2
- import type { SingleValueType, DefaultOptionType, InternalFieldNames, ShowCheckedStrategy } from '../Cascader';
1
+ import type { SingleValueType, DefaultOptionType, InternalFieldNames, ShowCheckedStrategy, LegacyKey } from '../Cascader';
3
2
  import type { GetEntities } from '../hooks/useEntities';
4
- export declare function formatStrategyValues(pathKeys: React.Key[], getKeyPathEntities: GetEntities, showCheckedStrategy?: ShowCheckedStrategy): import("react").Key[];
3
+ export declare function formatStrategyValues(pathKeys: LegacyKey[], getKeyPathEntities: GetEntities, showCheckedStrategy?: ShowCheckedStrategy): LegacyKey[];
5
4
  export declare function toPathOptions(valueCells: SingleValueType, options: DefaultOptionType[], fieldNames: InternalFieldNames, stringMode?: boolean): {
6
5
  value: SingleValueType[number];
7
6
  index: number;
@@ -1,4 +1,2 @@
1
- import type { DefaultOptionType, FieldNames, InternalCascaderProps } from '../Cascader';
2
- declare function warningProps(props: InternalCascaderProps): void;
1
+ import type { DefaultOptionType, FieldNames } from '../Cascader';
3
2
  export declare function warningNullOptions(options: DefaultOptionType[], fieldNames: FieldNames): void;
4
- export default warningProps;
@@ -1,13 +1,4 @@
1
1
  import warning from "@rc-component/util/es/warning";
2
- function warningProps(props) {
3
- const {
4
- popupVisible,
5
- popupPlacement
6
- } = props;
7
- warning(popupVisible === undefined, '`popupVisible` is deprecated. Please use `open` instead.');
8
- warning(popupPlacement === undefined, '`popupPlacement` is deprecated. Please use `placement` instead.');
9
- }
10
-
11
2
  // value in Cascader options should not be null
12
3
  export function warningNullOptions(options, fieldNames) {
13
4
  if (options) {
@@ -25,5 +16,4 @@ export function warningNullOptions(options, fieldNames) {
25
16
  };
26
17
  recursiveOptions(options);
27
18
  }
28
- }
29
- export default warningProps;
19
+ }
package/lib/Cascader.d.ts CHANGED
@@ -37,14 +37,10 @@ interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOption
37
37
  expandTrigger?: 'hover' | 'click';
38
38
  options?: OptionType[];
39
39
  /** @private Internal usage. Do not use in your production. */
40
- dropdownPrefixCls?: string;
40
+ popupPrefixCls?: string;
41
41
  loadData?: (selectOptions: OptionType[]) => void;
42
- /** @deprecated Use `open` instead */
43
- popupVisible?: boolean;
44
42
  popupClassName?: string;
45
- dropdownMenuColumnStyle?: React.CSSProperties;
46
- /** @deprecated Use `placement` instead */
47
- popupPlacement?: Placement;
43
+ popupMenuColumnStyle?: React.CSSProperties;
48
44
  placement?: Placement;
49
45
  builtinPlacements?: BuildInPlacements;
50
46
  onPopupVisibleChange?: (open: boolean) => void;
@@ -66,6 +62,7 @@ export interface CascaderProps<OptionType extends DefaultOptionType = DefaultOpt
66
62
  onChange?: (value: GetValueType<OptionType, ValueField, Multiple>, selectOptions: GetOptionType<OptionType, Multiple>) => void;
67
63
  }
68
64
  export type SingleValueType = (string | number)[];
65
+ export type LegacyKey = string | number;
69
66
  export type InternalValueType = SingleValueType | SingleValueType[];
70
67
  export interface InternalFieldNames extends Required<FieldNames> {
71
68
  key: string;
package/lib/Cascader.js CHANGED
@@ -21,7 +21,7 @@ var _OptionList = _interopRequireDefault(require("./OptionList"));
21
21
  var _Panel = _interopRequireDefault(require("./Panel"));
22
22
  var _commonUtil = require("./utils/commonUtil");
23
23
  var _treeUtil = require("./utils/treeUtil");
24
- var _warningPropsUtil = _interopRequireWildcard(require("./utils/warningPropsUtil"));
24
+ var _warningPropsUtil = require("./utils/warningPropsUtil");
25
25
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
26
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
27
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -48,15 +48,12 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
48
48
  expandTrigger,
49
49
  // Options
50
50
  options,
51
- dropdownPrefixCls,
51
+ popupPrefixCls,
52
52
  loadData,
53
- // Open
54
- popupVisible,
55
53
  open,
56
54
  popupClassName,
57
- dropdownMenuColumnStyle,
55
+ popupMenuColumnStyle,
58
56
  popupStyle: customPopupStyle,
59
- popupPlacement,
60
57
  placement,
61
58
  onPopupVisibleChange,
62
59
  // Icon
@@ -98,7 +95,7 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
98
95
  }
99
96
  };
100
97
  const [mergedShowSearch, searchConfig] = (0, _useSearchConfig.default)(showSearch);
101
- const searchOptions = (0, _useSearchOptions.default)(mergedSearchValue, mergedOptions, mergedFieldNames, dropdownPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
98
+ const searchOptions = (0, _useSearchOptions.default)(mergedSearchValue, mergedOptions, mergedFieldNames, popupPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
102
99
 
103
100
  // =========================== Values ===========================
104
101
  const getMissingValues = (0, _useMissingValues.default)(mergedOptions, mergedFieldNames);
@@ -148,17 +145,12 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
148
145
  } = info.values[0];
149
146
  onInternalSelect(valueCells);
150
147
  };
151
-
152
- // ============================ Open ============================
153
- const mergedOpen = open !== undefined ? open : popupVisible;
154
- const mergedPlacement = placement || popupPlacement;
155
148
  const onInternalPopupVisibleChange = nextVisible => {
156
149
  onPopupVisibleChange?.(nextVisible);
157
150
  };
158
151
 
159
152
  // ========================== Warning ===========================
160
153
  if (process.env.NODE_ENV !== 'production') {
161
- (0, _warningPropsUtil.default)(props);
162
154
  (0, _warningPropsUtil.warningNullOptions)(mergedOptions, mergedFieldNames);
163
155
  }
164
156
 
@@ -172,14 +164,14 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
172
164
  onSelect: onInternalSelect,
173
165
  checkable,
174
166
  searchOptions,
175
- dropdownPrefixCls,
167
+ popupPrefixCls,
176
168
  loadData,
177
169
  expandTrigger,
178
170
  expandIcon,
179
171
  loadingIcon,
180
- dropdownMenuColumnStyle,
172
+ popupMenuColumnStyle,
181
173
  optionRender
182
- }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, dropdownPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, dropdownMenuColumnStyle, optionRender]);
174
+ }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, popupPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, popupMenuColumnStyle, optionRender]);
183
175
 
184
176
  // ==============================================================
185
177
  // == Render ==
@@ -221,9 +213,9 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
221
213
  emptyOptions: emptyOptions
222
214
  // Open
223
215
  ,
224
- open: mergedOpen,
216
+ open: open,
225
217
  popupClassName: popupClassName,
226
- placement: mergedPlacement,
218
+ placement: placement,
227
219
  onPopupVisibleChange: onInternalPopupVisibleChange
228
220
  // Children
229
221
  ,
@@ -3,5 +3,5 @@ export interface CacheContentProps {
3
3
  children?: React.ReactNode;
4
4
  open?: boolean;
5
5
  }
6
- declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
6
+ declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>;
7
7
  export default CacheContent;
@@ -32,13 +32,14 @@ function Column({
32
32
  }) {
33
33
  const menuPrefixCls = `${prefixCls}-menu`;
34
34
  const menuItemPrefixCls = `${prefixCls}-menu-item`;
35
+ const menuRef = React.useRef(null);
35
36
  const {
36
37
  fieldNames,
37
38
  changeOnSelect,
38
39
  expandTrigger,
39
40
  expandIcon,
40
41
  loadingIcon,
41
- dropdownMenuColumnStyle,
42
+ popupMenuColumnStyle,
42
43
  optionRender
43
44
  } = React.useContext(_context.default);
44
45
  const hoverOpen = expandTrigger === 'hover';
@@ -79,10 +80,23 @@ function Column({
79
80
  fullPathKey
80
81
  };
81
82
  }), [options, checkedSet, fieldNames, halfCheckedSet, loadingKeys, prevValuePath]);
83
+ React.useEffect(() => {
84
+ if (menuRef.current) {
85
+ const selector = `.${menuItemPrefixCls}-active`;
86
+ const activeElement = menuRef.current.querySelector(selector);
87
+ if (activeElement) {
88
+ activeElement.scrollIntoView({
89
+ block: 'nearest',
90
+ inline: 'nearest'
91
+ });
92
+ }
93
+ }
94
+ }, [activeValue, menuItemPrefixCls]);
82
95
 
83
96
  // ============================ Render ============================
84
97
  return /*#__PURE__*/React.createElement("ul", {
85
98
  className: menuPrefixCls,
99
+ ref: menuRef,
86
100
  role: "menu"
87
101
  }, optionInfoList.map(({
88
102
  disabled,
@@ -133,7 +147,7 @@ function Column({
133
147
  [`${menuItemPrefixCls}-disabled`]: isOptionDisabled(disabled),
134
148
  [`${menuItemPrefixCls}-loading`]: isLoading
135
149
  }),
136
- style: dropdownMenuColumnStyle,
150
+ style: popupMenuColumnStyle,
137
151
  role: "menuitemcheckbox",
138
152
  title: title,
139
153
  "aria-checked": checked,
@@ -38,11 +38,11 @@ const RawOptionList = /*#__PURE__*/React.forwardRef((props, ref) => {
38
38
  changeOnSelect,
39
39
  onSelect,
40
40
  searchOptions,
41
- dropdownPrefixCls,
41
+ popupPrefixCls,
42
42
  loadData,
43
43
  expandTrigger
44
44
  } = React.useContext(_context.default);
45
- const mergedPrefixCls = dropdownPrefixCls || prefixCls;
45
+ const mergedPrefixCls = popupPrefixCls || prefixCls;
46
46
 
47
47
  // ========================= loadData =========================
48
48
  const [loadingKeys, setLoadingKeys] = React.useState([]);
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
1
+ import { LegacyKey } from "../Cascader";
2
2
  /**
3
3
  * Control the active open options path.
4
4
  */
5
- declare const useActive: (multiple?: boolean, open?: boolean) => [React.Key[], (activeValueCells: React.Key[]) => void];
5
+ declare const useActive: (multiple?: boolean, open?: boolean) => [LegacyKey[], (activeValueCells: LegacyKey[]) => void];
6
6
  export default useActive;
@@ -1,7 +1,7 @@
1
1
  import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
- import type { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
4
- declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: React.Key[], setActiveValueCells: (activeValueCells: React.Key[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
3
+ import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
+ declare const _default: (ref: React.Ref<RefOptionListProps>, options: DefaultOptionType[], fieldNames: InternalFieldNames, activeValueCells: LegacyKey[], setActiveValueCells: (activeValueCells: LegacyKey[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
5
5
  direction?: "ltr" | "rtl" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
package/lib/Panel.js CHANGED
@@ -94,12 +94,12 @@ function Panel(props) {
94
94
  onSelect: onInternalSelect,
95
95
  checkable,
96
96
  searchOptions: [],
97
- dropdownPrefixCls: undefined,
97
+ popupPrefixCls: undefined,
98
98
  loadData,
99
99
  expandTrigger,
100
100
  expandIcon,
101
101
  loadingIcon,
102
- dropdownMenuColumnStyle: undefined
102
+ popupMenuColumnStyle: undefined
103
103
  }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, loadData, expandTrigger, expandIcon, loadingIcon]);
104
104
 
105
105
  // ========================= Render =========================
package/lib/context.d.ts CHANGED
@@ -9,12 +9,12 @@ export interface CascaderContextProps {
9
9
  onSelect: (valuePath: SingleValueType) => void;
10
10
  checkable?: boolean | React.ReactNode;
11
11
  searchOptions: DefaultOptionType[];
12
- dropdownPrefixCls?: string;
12
+ popupPrefixCls?: string;
13
13
  loadData?: (selectOptions: DefaultOptionType[]) => void;
14
14
  expandTrigger?: 'hover' | 'click';
15
15
  expandIcon?: React.ReactNode;
16
16
  loadingIcon?: React.ReactNode;
17
- dropdownMenuColumnStyle?: React.CSSProperties;
17
+ popupMenuColumnStyle?: React.CSSProperties;
18
18
  optionRender?: CascaderProps['optionRender'];
19
19
  }
20
20
  declare const CascaderContext: React.Context<CascaderContextProps>;
@@ -1,5 +1,5 @@
1
1
  import type { DefaultOptionType, InternalFieldNames } from '../Cascader';
2
- import type { DataEntity } from 'rc-tree/lib/interface';
2
+ import type { DataEntity } from '@rc-component/tree/lib/interface';
3
3
  export interface OptionsInfo {
4
4
  keyEntities: Record<string, DataEntity>;
5
5
  pathKeyEntities: Record<string, DataEntity>;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var React = _interopRequireWildcard(require("react"));
8
- var _treeUtil = require("rc-tree/lib/utils/treeUtil");
8
+ var _treeUtil = require("@rc-component/tree/lib/utils/treeUtil");
9
9
  var _commonUtil = require("../utils/commonUtil");
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -1,9 +1,8 @@
1
- import * as React from 'react';
2
1
  import type { DefaultOptionType } from '..';
3
- import type { InternalFieldNames, SingleValueType } from '../Cascader';
2
+ import type { InternalFieldNames, SingleValueType, LegacyKey } from '../Cascader';
4
3
  import { type GetEntities } from './useEntities';
5
4
  export default function useOptions(mergedFieldNames: InternalFieldNames, options?: DefaultOptionType[]): [
6
5
  mergedOptions: DefaultOptionType[],
7
6
  getPathKeyEntities: GetEntities,
8
- getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[]
7
+ getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[]
9
8
  ];
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
- import type { InternalValueType, ShowCheckedStrategy, SingleValueType } from '../Cascader';
1
+ import type { InternalValueType, LegacyKey, ShowCheckedStrategy, SingleValueType } from '../Cascader';
3
2
  import type { GetEntities } from './useEntities';
4
- export default function useSelect(multiple: boolean, triggerChange: (nextValues: InternalValueType) => void, checkedValues: SingleValueType[], halfCheckedValues: SingleValueType[], missingCheckedValues: SingleValueType[], getPathKeyEntities: GetEntities, getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[], showCheckedStrategy?: ShowCheckedStrategy): (valuePath: SingleValueType) => void;
3
+ export default function useSelect(multiple: boolean, triggerChange: (nextValues: InternalValueType) => void, checkedValues: SingleValueType[], halfCheckedValues: SingleValueType[], missingCheckedValues: SingleValueType[], getPathKeyEntities: GetEntities, getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[], showCheckedStrategy?: ShowCheckedStrategy): (valuePath: SingleValueType) => void;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = useSelect;
7
- var _conductUtil = require("rc-tree/lib/utils/conductUtil");
7
+ var _conductUtil = require("@rc-component/tree/lib/utils/conductUtil");
8
8
  var _commonUtil = require("../utils/commonUtil");
9
9
  var _treeUtil = require("../utils/treeUtil");
10
10
  function useSelect(multiple, triggerChange, checkedValues, halfCheckedValues, missingCheckedValues, getPathKeyEntities, getValueByKeyPath, showCheckedStrategy) {
@@ -1,8 +1,7 @@
1
- import type { DataEntity } from 'rc-tree/lib/interface';
2
- import * as React from 'react';
3
- import type { SingleValueType } from '../Cascader';
1
+ import type { DataEntity } from '@rc-component/tree/lib/interface';
2
+ import type { LegacyKey, SingleValueType } from '../Cascader';
4
3
  import type { GetMissValues } from './useMissingValues';
5
- export default function useValues(multiple: boolean, rawValues: SingleValueType[], getPathKeyEntities: () => Record<string, DataEntity>, getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[], getMissingValues: GetMissValues): [
4
+ export default function useValues(multiple: boolean, rawValues: SingleValueType[], getPathKeyEntities: () => Record<string, DataEntity>, getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[], getMissingValues: GetMissValues): [
6
5
  checkedValues: SingleValueType[],
7
6
  halfCheckedValues: SingleValueType[],
8
7
  missingCheckedValues: SingleValueType[]
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = useValues;
7
- var _conductUtil = require("rc-tree/lib/utils/conductUtil");
7
+ var _conductUtil = require("@rc-component/tree/lib/utils/conductUtil");
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
  var _commonUtil = require("../utils/commonUtil");
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -1,7 +1,6 @@
1
- /// <reference types="react" />
2
- import type { SingleValueType, DefaultOptionType, InternalFieldNames, ShowCheckedStrategy } from '../Cascader';
1
+ import type { SingleValueType, DefaultOptionType, InternalFieldNames, ShowCheckedStrategy, LegacyKey } from '../Cascader';
3
2
  import type { GetEntities } from '../hooks/useEntities';
4
- export declare function formatStrategyValues(pathKeys: React.Key[], getKeyPathEntities: GetEntities, showCheckedStrategy?: ShowCheckedStrategy): import("react").Key[];
3
+ export declare function formatStrategyValues(pathKeys: LegacyKey[], getKeyPathEntities: GetEntities, showCheckedStrategy?: ShowCheckedStrategy): LegacyKey[];
5
4
  export declare function toPathOptions(valueCells: SingleValueType, options: DefaultOptionType[], fieldNames: InternalFieldNames, stringMode?: boolean): {
6
5
  value: SingleValueType[number];
7
6
  index: number;
@@ -1,4 +1,2 @@
1
- import type { DefaultOptionType, FieldNames, InternalCascaderProps } from '../Cascader';
2
- declare function warningProps(props: InternalCascaderProps): void;
1
+ import type { DefaultOptionType, FieldNames } from '../Cascader';
3
2
  export declare function warningNullOptions(options: DefaultOptionType[], fieldNames: FieldNames): void;
4
- export default warningProps;
@@ -3,19 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
7
6
  exports.warningNullOptions = warningNullOptions;
8
7
  var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
9
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- function warningProps(props) {
11
- const {
12
- popupVisible,
13
- popupPlacement
14
- } = props;
15
- (0, _warning.default)(popupVisible === undefined, '`popupVisible` is deprecated. Please use `open` instead.');
16
- (0, _warning.default)(popupPlacement === undefined, '`popupPlacement` is deprecated. Please use `placement` instead.');
17
- }
18
-
19
9
  // value in Cascader options should not be null
20
10
  function warningNullOptions(options, fieldNames) {
21
11
  if (options) {
@@ -33,5 +23,4 @@ function warningNullOptions(options, fieldNames) {
33
23
  };
34
24
  recursiveOptions(options);
35
25
  }
36
- }
37
- var _default = exports.default = warningProps;
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/cascader",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "cascade select ui component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -33,6 +33,7 @@
33
33
  "build": "dumi build",
34
34
  "compile": "father build",
35
35
  "coverage": "father test --coverage",
36
+ "tsc": "bunx tsc --noEmit",
36
37
  "deploy": "UMI_ENV=gh npm run build && gh-pages -d dist",
37
38
  "lint": "eslint src/ examples/ --ext .tsx,.ts,.jsx,.jsx",
38
39
  "now-build": "npm run build",
@@ -43,9 +44,9 @@
43
44
  },
44
45
  "dependencies": {
45
46
  "@rc-component/select": "~1.0.0",
47
+ "@rc-component/tree": "~1.0.0",
46
48
  "@rc-component/util": "^1.2.1",
47
- "classnames": "^2.3.1",
48
- "rc-tree": "~5.13.1"
49
+ "classnames": "^2.3.1"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@rc-component/father-plugin": "^2.0.2",
@@ -55,8 +56,8 @@
55
56
  "@types/classnames": "^2.2.6",
56
57
  "@types/enzyme": "^3.1.15",
57
58
  "@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",
60
61
  "@types/warning": "^3.0.0",
61
62
  "@umijs/fabric": "^4.0.0",
62
63
  "array-tree-filter": "^3.0.2",