rsuite 5.39.0 → 5.40.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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [5.40.0](https://github.com/rsuite/rsuite/compare/v5.39.0...v5.40.0) (2023-09-10)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **CheckTree:** searchKeyword is not updated as expected ([#3354](https://github.com/rsuite/rsuite/issues/3354)) ([b642da3](https://github.com/rsuite/rsuite/commit/b642da31c158481eeea8d46e9e3088edfb83acd1)), closes [#3196](https://github.com/rsuite/rsuite/issues/3196)
6
+
1
7
  # [5.39.0](https://github.com/rsuite/rsuite/compare/v5.38.0...v5.39.0) (2023-09-04)
2
8
 
3
9
  ### Bug Fixes
@@ -239,7 +239,7 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
239
239
  });
240
240
  }
241
241
 
242
- return (0, _utils2.getFormattedTree)(filteredData, flattenNodes, {
242
+ return (0, _utils2.getFormattedTree)(flattenNodes, filteredData, {
243
243
  childrenKey: childrenKey,
244
244
  cascade: cascade
245
245
  }).map(function (node) {
@@ -37,7 +37,7 @@ export declare function isEveryFirstLevelNodeUncheckable(nodes: TreeNodesType, u
37
37
  * @param {*} node
38
38
  */
39
39
  export declare function isNodeUncheckable(node: any, props: Required<Pick<CheckTreePickerProps, 'uncheckableItemValues' | 'valueKey'>>): boolean;
40
- export declare function getFormattedTree(data: any[], nodes: TreeNodesType, props: Required<Pick<CheckTreePickerProps, 'childrenKey' | 'cascade'>>): any[];
40
+ export declare function getFormattedTree(nodes: TreeNodesType, data: any[], props: Required<Pick<CheckTreePickerProps, 'childrenKey' | 'cascade'>>): any[];
41
41
  export declare function getDisabledState(nodes: TreeNodesType, node: TreeNodeType, props: Required<Pick<CheckTreePickerProps, 'disabledItemValues' | 'valueKey'>>): boolean;
42
42
  export declare function getCheckTreePickerDefaultValue(value: any[], uncheckableItemValues: any[]): any[];
43
43
  export declare function getSelectedItems(nodes: TreeNodesType, values: ValueType): TreeNodeType[];
@@ -130,7 +130,7 @@ function isNodeUncheckable(node, props) {
130
130
  });
131
131
  }
132
132
 
133
- function getFormattedTree(data, nodes, props) {
133
+ function getFormattedTree(nodes, data, props) {
134
134
  var childrenKey = props.childrenKey,
135
135
  cascade = props.cascade;
136
136
  return data.map(function (node) {
@@ -153,7 +153,7 @@ function getFormattedTree(data, nodes, props) {
153
153
  formatted.checkState = checkState;
154
154
 
155
155
  if (((_node$childrenKey = node[childrenKey]) === null || _node$childrenKey === void 0 ? void 0 : _node$childrenKey.length) > 0) {
156
- formatted[childrenKey] = getFormattedTree(formatted[childrenKey], nodes, props);
156
+ formatted[childrenKey] = getFormattedTree(nodes, formatted[childrenKey], props);
157
157
  }
158
158
  }
159
159
 
@@ -240,7 +240,7 @@ export declare function useTreeSearch<T>(props: TreeSearchProps<T>): {
240
240
  filteredData: T[];
241
241
  setFilteredData: (data: T[], searchKeyword: string) => void;
242
242
  setSearchKeyword: React.Dispatch<React.SetStateAction<string>>;
243
- handleSearch: (searchKeyword: string, event: React.ChangeEvent) => void;
243
+ handleSearch: (searchKeyword: string, event?: React.ChangeEvent) => void;
244
244
  };
245
245
  export declare function useGetTreeNodeChildren<T extends Record<string, unknown>>(treeData: T[], valueKey: string, childrenKey: string): {
246
246
  data: T[];
@@ -1051,9 +1051,7 @@ function useTreeSearch(props) {
1051
1051
  return data;
1052
1052
  }, [childrenKey, labelKey, searchBy]); // Use search keywords to filter options.
1053
1053
 
1054
- var _useState5 = (0, _react.useState)(function () {
1055
- return searchKeyword !== null && searchKeyword !== void 0 ? searchKeyword : '';
1056
- }),
1054
+ var _useState5 = (0, _react.useState)(searchKeyword !== null && searchKeyword !== void 0 ? searchKeyword : ''),
1057
1055
  searchKeywordState = _useState5[0],
1058
1056
  setSearchKeyword = _useState5[1];
1059
1057
 
@@ -1063,17 +1061,19 @@ function useTreeSearch(props) {
1063
1061
  filteredData = _useState6[0],
1064
1062
  setFilteredData = _useState6[1];
1065
1063
 
1066
- var handleSetFilteredData = (0, _react.useCallback)(function (data, searchKeyword) {
1067
- setFilteredData(filterVisibleData(data, searchKeyword));
1068
- }, [filterVisibleData]);
1069
-
1070
1064
  var handleSearch = function handleSearch(searchKeyword, event) {
1071
1065
  var filteredData = filterVisibleData(data, searchKeyword);
1072
1066
  setFilteredData(filteredData);
1073
1067
  setSearchKeyword(searchKeyword);
1074
- callback === null || callback === void 0 ? void 0 : callback(searchKeyword, filteredData, event);
1068
+ event && (callback === null || callback === void 0 ? void 0 : callback(searchKeyword, filteredData, event));
1075
1069
  };
1076
1070
 
1071
+ (0, _react.useEffect)(function () {
1072
+ handleSearch(searchKeyword !== null && searchKeyword !== void 0 ? searchKeyword : ''); // eslint-disable-next-line react-hooks/exhaustive-deps
1073
+ }, [searchKeyword]);
1074
+ var handleSetFilteredData = (0, _react.useCallback)(function (data, searchKeyword) {
1075
+ setFilteredData(filterVisibleData(data, searchKeyword));
1076
+ }, [filterVisibleData]);
1077
1077
  return {
1078
1078
  searchKeywordState: searchKeywordState,
1079
1079
  filteredData: filteredData,