rsuite 5.37.1 → 5.37.2

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.
@@ -111,16 +111,15 @@ var CheckPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
111
111
  onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchKeyword, event);
112
112
  }, [setFocusItemValue, onSearch, valueKey]); // Use search keywords to filter options.
113
113
 
114
- var _useSearch = useSearch({
114
+ var _useSearch = useSearch(data, {
115
115
  labelKey: labelKey,
116
- data: data,
117
116
  searchBy: searchBy,
118
117
  callback: handleSearchCallback
119
118
  }),
120
119
  searchKeyword = _useSearch.searchKeyword,
121
120
  filteredData = _useSearch.filteredData,
122
- setSearchKeyword = _useSearch.setSearchKeyword,
123
121
  handleSearch = _useSearch.handleSearch,
122
+ resetSearch = _useSearch.resetSearch,
124
123
  checkShouldDisplay = _useSearch.checkShouldDisplay; // Use component active state to support keyboard events.
125
124
 
126
125
 
@@ -229,11 +228,11 @@ var CheckPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
229
228
  onOpen === null || onOpen === void 0 ? void 0 : onOpen();
230
229
  }, [onOpen]);
231
230
  var handleExited = useCallback(function () {
232
- setSearchKeyword('');
231
+ resetSearch();
233
232
  setFocusItemValue(null);
234
233
  setActive(false);
235
234
  onClose === null || onClose === void 0 ? void 0 : onClose();
236
- }, [onClose, setFocusItemValue, setSearchKeyword]);
235
+ }, [onClose, setFocusItemValue, resetSearch]);
237
236
  usePublicMethods(ref, {
238
237
  triggerRef: triggerRef,
239
238
  overlayRef: overlayRef,
@@ -180,14 +180,13 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
180
180
  onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchKeyword, event);
181
181
  }, [disabledOptions, setFocusItemValue, valueKey, onSearch]); // Use search keywords to filter options.
182
182
 
183
- var _useSearch = useSearch({
183
+ var _useSearch = useSearch(getAllData(), {
184
184
  labelKey: labelKey,
185
- data: getAllData(),
186
185
  searchBy: searchBy,
187
186
  callback: handleSearchCallback
188
187
  }),
189
188
  searchKeyword = _useSearch.searchKeyword,
190
- setSearchKeyword = _useSearch.setSearchKeyword,
189
+ resetSearch = _useSearch.resetSearch,
191
190
  checkShouldDisplay = _useSearch.checkShouldDisplay,
192
191
  handleSearch = _useSearch.handleSearch; // Update the state when the data in props changes
193
192
 
@@ -300,7 +299,7 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
300
299
  var handleSelectItem = function handleSelectItem(value, item, event) {
301
300
  setValue(value);
302
301
  setFocusItemValue(value);
303
- setSearchKeyword('');
302
+ resetSearch();
304
303
  handleSelect(value, item, event);
305
304
  handleChange(value, event);
306
305
  handleClose();
@@ -326,7 +325,7 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
326
325
  }
327
326
 
328
327
  setValue(val);
329
- setSearchKeyword('');
328
+ resetSearch();
330
329
  setFocusItemValue(nextItemValue);
331
330
  handleSelect(val, item, event);
332
331
  handleChange(val, event);
@@ -372,10 +371,10 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
372
371
  }
373
372
 
374
373
  setValue(val);
375
- setSearchKeyword('');
374
+ resetSearch();
376
375
  handleSelect(val, focusItem, event);
377
376
  handleChange(val, event);
378
- }, [cloneValue, getAllData, focusItemValue, disabledItemValues, disabledOptions, setValue, setSearchKeyword, handleSelect, handleChange, valueKey, createOption]);
377
+ }, [cloneValue, getAllData, focusItemValue, disabledItemValues, disabledOptions, setValue, resetSearch, handleSelect, handleChange, valueKey, createOption]);
379
378
  var handleMenuItemKeyPress = useCallback(function (event) {
380
379
  if (!focusItemValue || !controlledData) {
381
380
  return;
@@ -399,7 +398,7 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
399
398
  }
400
399
 
401
400
  setValue(focusItemValue);
402
- setSearchKeyword('');
401
+ resetSearch();
403
402
 
404
403
  if (focusItem) {
405
404
  handleSelect(focusItemValue, focusItem, event);
@@ -407,7 +406,7 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
407
406
 
408
407
  handleChange(focusItemValue, event);
409
408
  handleClose();
410
- }, [setValue, disabledItemValues, controlledData, focusItemValue, valueKey, searchKeyword, handleClose, setSearchKeyword, createOption, getAllData, handleChange, handleSelect]);
409
+ }, [setValue, disabledItemValues, controlledData, focusItemValue, valueKey, searchKeyword, handleClose, resetSearch, createOption, getAllData, handleChange, handleSelect]);
411
410
  usePublicMethods(ref, {
412
411
  triggerRef: triggerRef,
413
412
  overlayRef: overlayRef,
@@ -443,7 +442,7 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
443
442
 
444
443
  setValue(null);
445
444
  setFocusItemValue(null);
446
- setSearchKeyword('');
445
+ resetSearch();
447
446
 
448
447
  if (multi) {
449
448
  handleChange([], event);
@@ -452,7 +451,7 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
452
451
  }
453
452
 
454
453
  onClean === null || onClean === void 0 ? void 0 : onClean(event);
455
- }, [disabled, searchKeyword, setValue, setFocusItemValue, setSearchKeyword, multi, onClean, handleChange]);
454
+ }, [disabled, searchKeyword, setValue, setFocusItemValue, resetSearch, multi, onClean, handleChange]);
456
455
  var events = {
457
456
  onMenuPressBackspace: multi ? removeLastItem : handleClean,
458
457
  onMenuKeyDown: onKeyDown,
@@ -492,9 +491,9 @@ var InputPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
492
491
  }, events, rest));
493
492
  var handleExited = useCallback(function () {
494
493
  setFocusItemValue(multi ? value === null || value === void 0 ? void 0 : value[0] : value);
495
- setSearchKeyword('');
494
+ resetSearch();
496
495
  onClose === null || onClose === void 0 ? void 0 : onClose();
497
- }, [setFocusItemValue, setSearchKeyword, onClose, value, multi]);
496
+ }, [setFocusItemValue, resetSearch, onClose, value, multi]);
498
497
  var handleFocus = useCallback(function () {
499
498
  if (!readOnly) {
500
499
  var _triggerRef$current4;
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { AnimationEventProps, StandardProps, TypeAttributes } from '../@types/common';
4
4
  import { PositionChildProps } from './Position';
5
5
  export declare type OverlayTriggerType = 'click' | 'hover' | 'focus' | 'active' | 'contextMenu' | 'none';
6
- export interface OverlayTriggerProps extends StandardProps, AnimationEventProps {
6
+ export interface OverlayTriggerProps extends Omit<StandardProps, 'children'>, AnimationEventProps {
7
7
  /** Triggering events */
8
8
  trigger?: OverlayTriggerType | OverlayTriggerType[];
9
9
  /** Display placement */
@@ -89,25 +89,22 @@ export interface ToggleKeyDownEventProps {
89
89
  * @param props
90
90
  */
91
91
  export declare const useToggleKeyDownEvent: (props: ToggleKeyDownEventProps) => (event: React.KeyboardEvent) => void;
92
- export interface SearchProps<TItem extends Record<string, unknown>, TLabel> {
92
+ interface SearchOptions<T> {
93
93
  labelKey: string;
94
- data: TItem[];
95
- searchBy?: (keyword: string, label: TLabel, item: TItem) => boolean;
96
- callback?: (keyword: string, data: TItem[], event: React.SyntheticEvent) => void;
94
+ searchBy?: (keyword: string, label: any, item: T) => boolean;
95
+ callback?: (keyword: string, data: T[], event: React.SyntheticEvent) => void;
97
96
  }
98
- declare type UseSearchResult<TItem extends Record<string, unknown>> = {
97
+ declare type UseSearchResult<T> = {
99
98
  searchKeyword: string;
100
- filteredData: TItem[];
101
- updateFilteredData: (nextData: TItem[]) => void;
102
- setSearchKeyword: (value: string) => void;
103
- checkShouldDisplay: (item: TItem, keyword?: string) => boolean;
99
+ filteredData: T[];
100
+ checkShouldDisplay: (item: T, keyword?: string) => boolean;
104
101
  handleSearch: (searchKeyword: string, event: React.SyntheticEvent) => void;
102
+ resetSearch: () => void;
105
103
  };
106
104
  /**
107
105
  * A hook that handles search filter options
108
- * @param props
109
106
  */
110
- export declare function useSearch<TItem extends Record<string, unknown>, TLabel>(props: SearchProps<TItem, TLabel>): UseSearchResult<TItem>;
107
+ export declare function useSearch<T>(data: readonly T[], props: SearchOptions<T>): UseSearchResult<T>;
111
108
  export interface PickerDependentParameters {
112
109
  triggerRef?: React.RefObject<OverlayTriggerHandle>;
113
110
  rootRef?: React.RefObject<HTMLElement>;
@@ -6,7 +6,7 @@ import isFunction from 'lodash/isFunction';
6
6
  import isUndefined from 'lodash/isUndefined';
7
7
  import omit from 'lodash/omit';
8
8
  import find from 'lodash/find';
9
- import { findNodeOfTree, filterNodesOfTree } from '../utils/treeUtils';
9
+ import { findNodeOfTree } from '../utils/treeUtils';
10
10
  import { KEY_VALUES, useClassNames, shallowEqual, reactToString, placementPolyfill } from '../utils';
11
11
  import { getHeight } from 'dom-lib';
12
12
  var defaultNodeKeys = {
@@ -494,48 +494,49 @@ export var useToggleKeyDownEvent = function useToggleKeyDownEvent(props) {
494
494
 
495
495
  /**
496
496
  * A hook that handles search filter options
497
- * @param props
498
497
  */
499
- export function useSearch(props) {
498
+ export function useSearch(data, props) {
500
499
  var labelKey = props.labelKey,
501
- data = props.data,
502
500
  searchBy = props.searchBy,
503
501
  callback = props.callback; // Use search keywords to filter options.
504
502
 
505
503
  var _useState4 = useState(''),
506
504
  searchKeyword = _useState4[0],
507
505
  setSearchKeyword = _useState4[1];
506
+
507
+ var resetSearch = useCallback(function () {
508
+ setSearchKeyword('');
509
+ }, []);
508
510
  /**
509
511
  * Index of keyword in `label`
510
512
  * @param {node} label
511
513
  */
512
514
 
513
-
514
515
  var checkShouldDisplay = useCallback(function (item, keyword) {
515
- var label = item === null || item === void 0 ? void 0 : item[labelKey];
516
+ var checkValue = typeof item === 'object' ? item === null || item === void 0 ? void 0 : item[labelKey] : String(item);
516
517
 
517
518
  var _keyword = isUndefined(keyword) ? searchKeyword : keyword;
518
519
 
519
520
  if (typeof searchBy === 'function') {
520
- return searchBy(_keyword, label, item);
521
+ return searchBy(_keyword, checkValue, item);
521
522
  }
522
523
 
523
- return shouldDisplay(label, _keyword);
524
- }, [labelKey, searchBy, searchKeyword]);
525
- var updateFilteredData = useCallback(function (nextData) {
526
- setFilteredData(filterNodesOfTree(nextData, function (item) {
527
- return checkShouldDisplay(item);
528
- }));
529
- }, [checkShouldDisplay]);
524
+ return shouldDisplay(checkValue, _keyword);
525
+ }, [labelKey, searchBy, searchKeyword]); // TODO-Doma
526
+ // filteredData should be derived from data and searchKeyword
527
+ // This redundant state might be here for preventing callback firing multiple times
528
+ // Find out if this is the case and remove this state if possible
530
529
 
531
- var _useState5 = useState(filterNodesOfTree(data, function (item) {
532
- return checkShouldDisplay(item);
533
- })),
530
+ var _useState5 = useState(function () {
531
+ return data.filter(function (item) {
532
+ return checkShouldDisplay(item);
533
+ });
534
+ }),
534
535
  filteredData = _useState5[0],
535
536
  setFilteredData = _useState5[1];
536
537
 
537
538
  var handleSearch = function handleSearch(searchKeyword, event) {
538
- var filteredData = filterNodesOfTree(data, function (item) {
539
+ var filteredData = data.filter(function (item) {
539
540
  return checkShouldDisplay(item, searchKeyword);
540
541
  });
541
542
  setFilteredData(filteredData);
@@ -546,10 +547,9 @@ export function useSearch(props) {
546
547
  return {
547
548
  searchKeyword: searchKeyword,
548
549
  filteredData: filteredData,
549
- updateFilteredData: updateFilteredData,
550
- setSearchKeyword: setSearchKeyword,
551
550
  checkShouldDisplay: checkShouldDisplay,
552
- handleSearch: handleSearch
551
+ handleSearch: handleSearch,
552
+ resetSearch: resetSearch
553
553
  };
554
554
  }
555
555
 
@@ -4,7 +4,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
4
4
 
5
5
  var _templateObject;
6
6
 
7
- import React, { useRef, useState, useCallback, useEffect } from 'react';
7
+ import React, { useRef, useState, useCallback } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import pick from 'lodash/pick';
10
10
  import isUndefined from 'lodash/isUndefined';
@@ -97,9 +97,8 @@ var SelectPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
97
97
  onFocusItem = _useFocusItemValue.onKeyDown; // Use search keywords to filter options.
98
98
 
99
99
 
100
- var _useSearch = useSearch({
100
+ var _useSearch = useSearch(data, {
101
101
  labelKey: labelKey,
102
- data: data,
103
102
  searchBy: searchBy,
104
103
  callback: function callback(searchKeyword, filteredData, event) {
105
104
  var _filteredData$;
@@ -111,13 +110,9 @@ var SelectPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
111
110
  }),
112
111
  searchKeyword = _useSearch.searchKeyword,
113
112
  filteredData = _useSearch.filteredData,
114
- updateFilteredData = _useSearch.updateFilteredData,
115
- setSearchKeyword = _useSearch.setSearchKeyword,
116
- handleSearch = _useSearch.handleSearch;
113
+ resetSearch = _useSearch.resetSearch,
114
+ handleSearch = _useSearch.handleSearch; // Use component active state to support keyboard events.
117
115
 
118
- useEffect(function () {
119
- updateFilteredData(data);
120
- }, [data, updateFilteredData]); // Use component active state to support keyboard events.
121
116
 
122
117
  var _useState = useState(false),
123
118
  active = _useState[0],
@@ -182,11 +177,11 @@ var SelectPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
182
177
  }
183
178
  }, rest));
184
179
  var handleExited = useCallback(function () {
185
- setSearchKeyword('');
180
+ resetSearch();
186
181
  setActive(false);
187
182
  onSearch === null || onSearch === void 0 ? void 0 : onSearch('');
188
183
  onClose === null || onClose === void 0 ? void 0 : onClose();
189
- }, [onClose, setSearchKeyword, onSearch]);
184
+ }, [onClose, resetSearch, onSearch]);
190
185
  var handleEntered = useCallback(function () {
191
186
  setActive(true);
192
187
  setFocusItemValue(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.37.1",
3
+ "version": "5.37.2",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",