@rc-component/cascader 1.3.1 → 1.4.0

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.
package/README.md CHANGED
@@ -114,12 +114,6 @@ React.render(
114
114
  </tr>
115
115
  </thead>
116
116
  <tbody>
117
- <tr>
118
- <td>autoClearSearchValue</td>
119
- <td>boolean</td>
120
- <td>true</td>
121
- <td>Whether the current search will be cleared on selecting an item. Only applies when checkable</td>
122
- </tr>
123
117
  <tr>
124
118
  <td>options</td>
125
119
  <td>Object</td>
@@ -234,9 +228,28 @@ React.render(
234
228
  <td>>true</td>
235
229
  <td>hide popup on select</td>
236
230
  </tr>
231
+ <tr>
232
+ <td>showSearch</td>
233
+ <td>boolean | object</td>
234
+ <td>false</td>
235
+ <td>Whether show search input in single mode</td>
236
+ </tr>
237
237
  </tbody>
238
238
  </table>
239
239
 
240
+ ### showSearch
241
+
242
+ | Property | Description | Type | Default | Version |
243
+ | --- | --- | --- | --- | --- |
244
+ | autoClearSearchValue | Whether the current search will be cleared on selecting an item. Only applies when checkable| boolean | true |
245
+ | filter | The function will receive two arguments, inputValue and option, if the function returns true, the option will be included in the filtered set; Otherwise, it will be excluded | function(inputValue, path): boolean | - | |
246
+ | limit | Set the count of filtered items | number \| false | 50 | |
247
+ | matchInputWidth | Whether the width of list matches input, ([how it looks](https://github.com/ant-design/ant-design/issues/25779)) | boolean | true | |
248
+ | render | Used to render filtered options | function(inputValue, path): ReactNode | - | |
249
+ | sort | Used to sort filtered options | function(a, b, inputValue) | - | |
250
+ | searchValue | The current input "search" text | string | - | - |
251
+ | onSearch | called when input changed | function | - | - |
252
+
240
253
  ### option
241
254
 
242
255
  <table class="table table-bordered table-striped">
package/es/Cascader.d.ts CHANGED
@@ -12,12 +12,15 @@ export interface BaseOptionType {
12
12
  children?: DefaultOptionType[];
13
13
  }
14
14
  export type DefaultOptionType = BaseOptionType & Record<string, any>;
15
- export interface ShowSearchType<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> {
15
+ export interface SearchConfig<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> {
16
16
  filter?: (inputValue: string, options: OptionType[], fieldNames: FieldNames<OptionType, ValueField>) => boolean;
17
17
  render?: (inputValue: string, path: OptionType[], prefixCls: string, fieldNames: FieldNames<OptionType, ValueField>) => React.ReactNode;
18
18
  sort?: (a: OptionType[], b: OptionType[], inputValue: string, fieldNames: FieldNames<OptionType, ValueField>) => number;
19
19
  matchInputWidth?: boolean;
20
20
  limit?: number | false;
21
+ searchValue?: string;
22
+ onSearch?: (value: string) => void;
23
+ autoClearSearchValue?: boolean;
21
24
  }
22
25
  export type ShowCheckedStrategy = typeof SHOW_PARENT | typeof SHOW_CHILD;
23
26
  interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> extends Omit<BaseSelectPropsWithoutPrivate, 'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch'> {
@@ -30,9 +33,12 @@ interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOption
30
33
  displayRender?: (label: string[], selectedOptions?: OptionType[]) => React.ReactNode;
31
34
  checkable?: boolean | React.ReactNode;
32
35
  showCheckedStrategy?: ShowCheckedStrategy;
36
+ /** @deprecated please use showSearch.autoClearSearchValue */
33
37
  autoClearSearchValue?: boolean;
34
- showSearch?: boolean | ShowSearchType<OptionType>;
38
+ showSearch?: boolean | SearchConfig<OptionType>;
39
+ /** @deprecated please use showSearch.searchValue */
35
40
  searchValue?: string;
41
+ /** @deprecated please use showSearch.onSearch */
36
42
  onSearch?: (value: string) => void;
37
43
  expandTrigger?: 'hover' | 'click';
38
44
  options?: OptionType[];
package/es/Cascader.js CHANGED
@@ -31,9 +31,6 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
31
31
  displayRender,
32
32
  checkable,
33
33
  // Search
34
- autoClearSearchValue = true,
35
- searchValue,
36
- onSearch,
37
34
  showSearch,
38
35
  // Trigger
39
36
  expandTrigger,
@@ -77,6 +74,12 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
77
74
  const [mergedOptions, getPathKeyEntities, getValueByKeyPath] = useOptions(mergedFieldNames, options);
78
75
 
79
76
  // =========================== Search ===========================
77
+ const [mergedShowSearch, searchConfig] = useSearchConfig(showSearch, props);
78
+ const {
79
+ autoClearSearchValue = true,
80
+ searchValue,
81
+ onSearch
82
+ } = searchConfig;
80
83
  const [mergedSearchValue, setSearchValue] = useMergedState('', {
81
84
  value: searchValue,
82
85
  postState: search => search || ''
@@ -87,7 +90,6 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
87
90
  onSearch(searchText);
88
91
  }
89
92
  };
90
- const [mergedShowSearch, searchConfig] = useSearchConfig(showSearch);
91
93
  const searchOptions = useSearchOptions(mergedSearchValue, mergedOptions, mergedFieldNames, popupPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
92
94
 
93
95
  // =========================== Values ===========================
@@ -2,7 +2,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
3
  import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
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
- direction?: "ltr" | "rtl" | undefined;
5
+ direction?: "rtl" | "ltr" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
8
8
  open?: boolean | undefined;
@@ -1,2 +1,2 @@
1
- import type { CascaderProps, ShowSearchType } from '../Cascader';
2
- export default function useSearchConfig(showSearch?: CascaderProps['showSearch']): [boolean, ShowSearchType<import("../Cascader").DefaultOptionType, string>];
1
+ import type { CascaderProps, SearchConfig } from '../Cascader';
2
+ export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any): [boolean, SearchConfig<import("../Cascader").DefaultOptionType, string>];
@@ -1,14 +1,22 @@
1
1
  import warning from "@rc-component/util/es/warning";
2
2
  import * as React from 'react';
3
3
  // Convert `showSearch` to unique config
4
- export default function useSearchConfig(showSearch) {
4
+ export default function useSearchConfig(showSearch, props) {
5
+ const {
6
+ autoClearSearchValue,
7
+ searchValue,
8
+ onSearch
9
+ } = props;
5
10
  return React.useMemo(() => {
6
11
  if (!showSearch) {
7
12
  return [false, {}];
8
13
  }
9
14
  let searchConfig = {
10
15
  matchInputWidth: true,
11
- limit: 50
16
+ limit: 50,
17
+ autoClearSearchValue,
18
+ searchValue,
19
+ onSearch
12
20
  };
13
21
  if (showSearch && typeof showSearch === 'object') {
14
22
  searchConfig = {
@@ -23,5 +31,5 @@ export default function useSearchConfig(showSearch) {
23
31
  }
24
32
  }
25
33
  return [true, searchConfig];
26
- }, [showSearch]);
34
+ }, [showSearch, autoClearSearchValue, searchValue, onSearch]);
27
35
  }
@@ -1,4 +1,4 @@
1
- import type { DefaultOptionType, InternalFieldNames, ShowSearchType } from '../Cascader';
1
+ import type { DefaultOptionType, InternalFieldNames, SearchConfig } from '../Cascader';
2
2
  export declare const SEARCH_MARK = "__rc_cascader_search_mark__";
3
- declare const useSearchOptions: (search: string, options: DefaultOptionType[], fieldNames: InternalFieldNames, prefixCls: string, config: ShowSearchType, enableHalfPath?: boolean) => DefaultOptionType[];
3
+ declare const useSearchOptions: (search: string, options: DefaultOptionType[], fieldNames: InternalFieldNames, prefixCls: string, config: SearchConfig, enableHalfPath?: boolean) => DefaultOptionType[];
4
4
  export default useSearchOptions;
package/es/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Cascader from './Cascader';
2
2
  import Panel from './Panel';
3
- export type { BaseOptionType, DefaultOptionType, CascaderProps, FieldNames, ShowSearchType, CascaderRef, } from './Cascader';
3
+ export type { BaseOptionType, DefaultOptionType, CascaderProps, FieldNames, SearchConfig, CascaderRef, } from './Cascader';
4
4
  export { Panel };
5
5
  export default Cascader;
package/lib/Cascader.d.ts CHANGED
@@ -12,12 +12,15 @@ export interface BaseOptionType {
12
12
  children?: DefaultOptionType[];
13
13
  }
14
14
  export type DefaultOptionType = BaseOptionType & Record<string, any>;
15
- export interface ShowSearchType<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> {
15
+ export interface SearchConfig<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> {
16
16
  filter?: (inputValue: string, options: OptionType[], fieldNames: FieldNames<OptionType, ValueField>) => boolean;
17
17
  render?: (inputValue: string, path: OptionType[], prefixCls: string, fieldNames: FieldNames<OptionType, ValueField>) => React.ReactNode;
18
18
  sort?: (a: OptionType[], b: OptionType[], inputValue: string, fieldNames: FieldNames<OptionType, ValueField>) => number;
19
19
  matchInputWidth?: boolean;
20
20
  limit?: number | false;
21
+ searchValue?: string;
22
+ onSearch?: (value: string) => void;
23
+ autoClearSearchValue?: boolean;
21
24
  }
22
25
  export type ShowCheckedStrategy = typeof SHOW_PARENT | typeof SHOW_CHILD;
23
26
  interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> extends Omit<BaseSelectPropsWithoutPrivate, 'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch'> {
@@ -30,9 +33,12 @@ interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOption
30
33
  displayRender?: (label: string[], selectedOptions?: OptionType[]) => React.ReactNode;
31
34
  checkable?: boolean | React.ReactNode;
32
35
  showCheckedStrategy?: ShowCheckedStrategy;
36
+ /** @deprecated please use showSearch.autoClearSearchValue */
33
37
  autoClearSearchValue?: boolean;
34
- showSearch?: boolean | ShowSearchType<OptionType>;
38
+ showSearch?: boolean | SearchConfig<OptionType>;
39
+ /** @deprecated please use showSearch.searchValue */
35
40
  searchValue?: string;
41
+ /** @deprecated please use showSearch.onSearch */
36
42
  onSearch?: (value: string) => void;
37
43
  expandTrigger?: 'hover' | 'click';
38
44
  options?: OptionType[];
package/lib/Cascader.js CHANGED
@@ -40,9 +40,6 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
40
40
  displayRender,
41
41
  checkable,
42
42
  // Search
43
- autoClearSearchValue = true,
44
- searchValue,
45
- onSearch,
46
43
  showSearch,
47
44
  // Trigger
48
45
  expandTrigger,
@@ -86,6 +83,12 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
86
83
  const [mergedOptions, getPathKeyEntities, getValueByKeyPath] = (0, _useOptions.default)(mergedFieldNames, options);
87
84
 
88
85
  // =========================== Search ===========================
86
+ const [mergedShowSearch, searchConfig] = (0, _useSearchConfig.default)(showSearch, props);
87
+ const {
88
+ autoClearSearchValue = true,
89
+ searchValue,
90
+ onSearch
91
+ } = searchConfig;
89
92
  const [mergedSearchValue, setSearchValue] = (0, _useMergedState.default)('', {
90
93
  value: searchValue,
91
94
  postState: search => search || ''
@@ -96,7 +99,6 @@ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
96
99
  onSearch(searchText);
97
100
  }
98
101
  };
99
- const [mergedShowSearch, searchConfig] = (0, _useSearchConfig.default)(showSearch);
100
102
  const searchOptions = (0, _useSearchOptions.default)(mergedSearchValue, mergedOptions, mergedFieldNames, popupPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
101
103
 
102
104
  // =========================== Values ===========================
@@ -2,7 +2,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
2
2
  import * as React from 'react';
3
3
  import type { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
4
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
- direction?: "ltr" | "rtl" | undefined;
5
+ direction?: "rtl" | "ltr" | undefined;
6
6
  searchValue: string;
7
7
  toggleOpen: (open?: boolean) => void;
8
8
  open?: boolean | undefined;
@@ -1,2 +1,2 @@
1
- import type { CascaderProps, ShowSearchType } from '../Cascader';
2
- export default function useSearchConfig(showSearch?: CascaderProps['showSearch']): [boolean, ShowSearchType<import("../Cascader").DefaultOptionType, string>];
1
+ import type { CascaderProps, SearchConfig } from '../Cascader';
2
+ export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any): [boolean, SearchConfig<import("../Cascader").DefaultOptionType, string>];
@@ -10,14 +10,22 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
10
10
  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; }
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  // Convert `showSearch` to unique config
13
- function useSearchConfig(showSearch) {
13
+ function useSearchConfig(showSearch, props) {
14
+ const {
15
+ autoClearSearchValue,
16
+ searchValue,
17
+ onSearch
18
+ } = props;
14
19
  return React.useMemo(() => {
15
20
  if (!showSearch) {
16
21
  return [false, {}];
17
22
  }
18
23
  let searchConfig = {
19
24
  matchInputWidth: true,
20
- limit: 50
25
+ limit: 50,
26
+ autoClearSearchValue,
27
+ searchValue,
28
+ onSearch
21
29
  };
22
30
  if (showSearch && typeof showSearch === 'object') {
23
31
  searchConfig = {
@@ -32,5 +40,5 @@ function useSearchConfig(showSearch) {
32
40
  }
33
41
  }
34
42
  return [true, searchConfig];
35
- }, [showSearch]);
43
+ }, [showSearch, autoClearSearchValue, searchValue, onSearch]);
36
44
  }
@@ -1,4 +1,4 @@
1
- import type { DefaultOptionType, InternalFieldNames, ShowSearchType } from '../Cascader';
1
+ import type { DefaultOptionType, InternalFieldNames, SearchConfig } from '../Cascader';
2
2
  export declare const SEARCH_MARK = "__rc_cascader_search_mark__";
3
- declare const useSearchOptions: (search: string, options: DefaultOptionType[], fieldNames: InternalFieldNames, prefixCls: string, config: ShowSearchType, enableHalfPath?: boolean) => DefaultOptionType[];
3
+ declare const useSearchOptions: (search: string, options: DefaultOptionType[], fieldNames: InternalFieldNames, prefixCls: string, config: SearchConfig, enableHalfPath?: boolean) => DefaultOptionType[];
4
4
  export default useSearchOptions;
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Cascader from './Cascader';
2
2
  import Panel from './Panel';
3
- export type { BaseOptionType, DefaultOptionType, CascaderProps, FieldNames, ShowSearchType, CascaderRef, } from './Cascader';
3
+ export type { BaseOptionType, DefaultOptionType, CascaderProps, FieldNames, SearchConfig, CascaderRef, } from './Cascader';
4
4
  export { Panel };
5
5
  export default Cascader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/cascader",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "cascade select ui component for react",
5
5
  "keywords": [
6
6
  "react",