rsuite 5.16.2 → 5.16.5

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 (59) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/Picker/styles/index.less +1 -1
  3. package/cjs/AutoComplete/AutoComplete.d.ts +3 -1
  4. package/cjs/AutoComplete/AutoComplete.js +6 -2
  5. package/cjs/AutoComplete/test/AutoComplete.test.d.ts +1 -0
  6. package/cjs/AutoComplete/test/AutoComplete.test.js +23 -0
  7. package/cjs/Calendar/useCalendarDate.d.ts +1 -0
  8. package/cjs/Calendar/useCalendarDate.js +7 -1
  9. package/cjs/CheckTreePicker/CheckTreePicker.js +5 -0
  10. package/cjs/DatePicker/DatePicker.d.ts +1 -1
  11. package/cjs/DatePicker/DatePicker.js +5 -4
  12. package/cjs/DatePicker/Toolbar.js +1 -1
  13. package/cjs/DateRangePicker/DateRangePicker.d.ts +1 -1
  14. package/cjs/DateRangePicker/DateRangePicker.js +26 -5
  15. package/cjs/Overlay/OverlayTrigger.js +43 -34
  16. package/cjs/Picker/DropdownMenu.d.ts +1 -1
  17. package/cjs/Picker/PickerToggle.d.ts +1 -1
  18. package/cjs/Picker/PickerToggle.js +52 -27
  19. package/cjs/SelectPicker/SelectPicker.d.ts +2 -2
  20. package/cjs/SelectPicker/test/SelectPicker.test.js +10 -0
  21. package/cjs/Tree/Tree.d.ts +2 -2
  22. package/cjs/Tree/test/Tree.test.d.ts +1 -0
  23. package/cjs/Tree/test/Tree.test.js +18 -0
  24. package/cjs/utils/dateUtils.d.ts +1 -0
  25. package/cjs/utils/dateUtils.js +5 -1
  26. package/dist/rsuite-rtl.css +1 -1
  27. package/dist/rsuite-rtl.min.css +1 -1
  28. package/dist/rsuite-rtl.min.css.map +1 -1
  29. package/dist/rsuite.css +1 -1
  30. package/dist/rsuite.js +20 -9
  31. package/dist/rsuite.js.map +1 -1
  32. package/dist/rsuite.min.css +1 -1
  33. package/dist/rsuite.min.css.map +1 -1
  34. package/dist/rsuite.min.js +1 -1
  35. package/dist/rsuite.min.js.map +1 -1
  36. package/esm/AutoComplete/AutoComplete.d.ts +3 -1
  37. package/esm/AutoComplete/AutoComplete.js +6 -2
  38. package/esm/AutoComplete/test/AutoComplete.test.d.ts +1 -0
  39. package/esm/AutoComplete/test/AutoComplete.test.js +18 -0
  40. package/esm/Calendar/useCalendarDate.d.ts +1 -0
  41. package/esm/Calendar/useCalendarDate.js +7 -1
  42. package/esm/CheckTreePicker/CheckTreePicker.js +5 -0
  43. package/esm/DatePicker/DatePicker.d.ts +1 -1
  44. package/esm/DatePicker/DatePicker.js +5 -4
  45. package/esm/DatePicker/Toolbar.js +1 -1
  46. package/esm/DateRangePicker/DateRangePicker.d.ts +1 -1
  47. package/esm/DateRangePicker/DateRangePicker.js +26 -5
  48. package/esm/Overlay/OverlayTrigger.js +44 -35
  49. package/esm/Picker/DropdownMenu.d.ts +1 -1
  50. package/esm/Picker/PickerToggle.d.ts +1 -1
  51. package/esm/Picker/PickerToggle.js +52 -27
  52. package/esm/SelectPicker/SelectPicker.d.ts +2 -2
  53. package/esm/SelectPicker/test/SelectPicker.test.js +9 -0
  54. package/esm/Tree/Tree.d.ts +2 -2
  55. package/esm/Tree/test/Tree.test.d.ts +1 -0
  56. package/esm/Tree/test/Tree.test.js +11 -0
  57. package/esm/utils/dateUtils.d.ts +1 -0
  58. package/esm/utils/dateUtils.js +1 -0
  59. package/package.json +1 -1
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { PickerComponent } from '../Picker';
3
3
  import { WithAsProps, FormControlPickerProps, TypeAttributes, ItemDataType } from '../@types/common';
4
4
  export declare type ValueType = string;
5
- export interface AutoCompleteProps<T = ValueType> extends WithAsProps, FormControlPickerProps<T, any, ItemDataType> {
5
+ export interface AutoCompleteProps<T = ValueType> extends WithAsProps, FormControlPickerProps<T, any, ItemDataType | string> {
6
6
  /** Additional classes for menu */
7
7
  menuClassName?: string;
8
8
  /** The placement of component */
@@ -13,6 +13,8 @@ export interface AutoCompleteProps<T = ValueType> extends WithAsProps, FormContr
13
13
  open?: boolean;
14
14
  /** Placeholder text */
15
15
  placeholder?: string;
16
+ /** The width of the menu will automatically follow the width of the input box */
17
+ menuAutoWidth?: boolean;
16
18
  /** Custom filter function to determine whether the item will be displayed */
17
19
  filterBy?: (value: string, item: ItemDataType) => boolean;
18
20
  /** Called when a option is selected */
@@ -26,6 +26,8 @@ var AutoComplete = /*#__PURE__*/React.forwardRef(function (props, ref) {
26
26
  classPrefix = _props$classPrefix === void 0 ? 'auto-complete' : _props$classPrefix,
27
27
  _props$defaultValue = props.defaultValue,
28
28
  defaultValue = _props$defaultValue === void 0 ? '' : _props$defaultValue,
29
+ _props$menuAutoWidth = props.menuAutoWidth,
30
+ menuAutoWidth = _props$menuAutoWidth === void 0 ? true : _props$menuAutoWidth,
29
31
  data = props.data,
30
32
  valueProp = props.value,
31
33
  open = props.open,
@@ -43,7 +45,7 @@ var AutoComplete = /*#__PURE__*/React.forwardRef(function (props, ref) {
43
45
  onFocus = props.onFocus,
44
46
  onBlur = props.onBlur,
45
47
  onMenuFocus = props.onMenuFocus,
46
- rest = _objectWithoutPropertiesLoose(props, ["as", "disabled", "className", "placement", "selectOnEnter", "classPrefix", "defaultValue", "data", "value", "open", "style", "menuClassName", "id", "renderMenu", "renderMenuItem", "onSelect", "filterBy", "onKeyDown", "onChange", "onClose", "onOpen", "onFocus", "onBlur", "onMenuFocus"]);
48
+ rest = _objectWithoutPropertiesLoose(props, ["as", "disabled", "className", "placement", "selectOnEnter", "classPrefix", "defaultValue", "menuAutoWidth", "data", "value", "open", "style", "menuClassName", "id", "renderMenu", "renderMenuItem", "onSelect", "filterBy", "onKeyDown", "onChange", "onClose", "onOpen", "onFocus", "onBlur", "onMenuFocus"]);
47
49
 
48
50
  var datalist = transformData(data);
49
51
 
@@ -184,7 +186,8 @@ var AutoComplete = /*#__PURE__*/React.forwardRef(function (props, ref) {
184
186
  style: styles,
185
187
  className: className,
186
188
  onKeyDown: handleKeyDownEvent,
187
- target: triggerRef
189
+ target: triggerRef,
190
+ autoWidth: menuAutoWidth
188
191
  }, renderMenu ? renderMenu(menu) : menu);
189
192
  };
190
193
 
@@ -219,6 +222,7 @@ AutoComplete.propTypes = _extends({}, animationPropTypes, {
219
222
  defaultValue: PropTypes.string,
220
223
  className: PropTypes.string,
221
224
  menuClassName: PropTypes.string,
225
+ menuAutoWidth: PropTypes.bool,
222
226
  placement: PropTypes.oneOf(PLACEMENT),
223
227
  onFocus: PropTypes.func,
224
228
  onMenuFocus: PropTypes.func,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import AutoComplete from '../AutoComplete';
3
+
4
+ /*#__PURE__*/
5
+ React.createElement(AutoComplete, {
6
+ data: ['item1', 'item2']
7
+ });
8
+
9
+ /*#__PURE__*/
10
+ React.createElement(AutoComplete, {
11
+ data: [{
12
+ label: 'item1',
13
+ value: 'item1'
14
+ }, {
15
+ label: 'item2',
16
+ value: 'item2'
17
+ }]
18
+ });
@@ -1,5 +1,6 @@
1
1
  declare const useCalendarDate: (value: Date | null | undefined, defaultDate: Date | undefined) => {
2
2
  calendarDate: Date;
3
3
  setCalendarDate: (date: Date | undefined) => void;
4
+ resetCalendarDate: () => void;
4
5
  };
5
6
  export default useCalendarDate;
@@ -15,6 +15,11 @@ var useCalendarDate = function useCalendarDate(value, defaultDate) {
15
15
  setValue(date);
16
16
  }
17
17
  }, [calendarDate]);
18
+ var resetCalendarDate = useCallback(function () {
19
+ var _ref2;
20
+
21
+ setValue((_ref2 = value !== null && value !== void 0 ? value : defaultDate) !== null && _ref2 !== void 0 ? _ref2 : new Date());
22
+ }, [defaultDate, value]);
18
23
  useUpdateEffect(function () {
19
24
  var _valueRef$current;
20
25
 
@@ -25,7 +30,8 @@ var useCalendarDate = function useCalendarDate(value, defaultDate) {
25
30
  }, [value]);
26
31
  return {
27
32
  calendarDate: calendarDate,
28
- setCalendarDate: setCalendarDate
33
+ setCalendarDate: setCalendarDate,
34
+ resetCalendarDate: resetCalendarDate
29
35
  };
30
36
  };
31
37
 
@@ -566,6 +566,11 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
566
566
  var visibleChildren = _isUndefined(searchKeywordState) || searchKeywordState.length === 0 ? !!children : hasVisibleChildren(node, childrenKey);
567
567
 
568
568
  var nodeProps = _extends({}, getTreeNodeProps(_extends({}, node, {
569
+ /**
570
+ * spread operator dont copy unenumerable properties
571
+ * so we need to copy them manually
572
+ */
573
+ parent: node.parent,
569
574
  expand: expand
570
575
  }), layer), {
571
576
  hasChildren: visibleChildren
@@ -5,7 +5,7 @@ import { PickerToggleProps } from '../Picker';
5
5
  import { FormControlBaseProps, PickerBaseProps, RsRefForwardingComponent } from '../@types/common';
6
6
  export type { RangeType } from './Toolbar';
7
7
  export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, FormControlBaseProps<Date | null>, Pick<PickerToggleProps, 'caretAs' | 'readOnly' | 'plaintext'> {
8
- /** Configure shortcut options */
8
+ /** Predefined date Ranges */
9
9
  ranges?: RangeType<Date>[];
10
10
  /** Calendar panel default presentation date and time */
11
11
  calendarDefaultDate?: Date;
@@ -77,7 +77,8 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
77
77
 
78
78
  var _useCalendarDate = useCalendarDate(valueProp, calendarDefaultDate),
79
79
  calendarDate = _useCalendarDate.calendarDate,
80
- setCalendarDate = _useCalendarDate.setCalendarDate;
80
+ setCalendarDate = _useCalendarDate.setCalendarDate,
81
+ resetCalendarDate = _useCalendarDate.resetCalendarDate;
81
82
 
82
83
  var _useState = useState(),
83
84
  inputState = _useState[0],
@@ -217,9 +218,9 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
217
218
  */
218
219
 
219
220
  var handleClean = useCallback(function (event) {
220
- setCalendarDate(new Date());
221
221
  updateValue(event, null);
222
- }, [setCalendarDate, updateValue]);
222
+ resetCalendarDate();
223
+ }, [resetCalendarDate, updateValue]);
223
224
  /**
224
225
  * Handle keyboard events.
225
226
  */
@@ -437,7 +438,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
437
438
  as: toggleAs,
438
439
  ref: targetRef,
439
440
  appearance: appearance,
440
- input: true,
441
+ editable: true,
441
442
  inputValue: value ? formatDate(value, formatStr) : '',
442
443
  inputPlaceholder: typeof placeholder === 'string' && placeholder ? placeholder : formatStr,
443
444
  inputMask: DateUtils.getDateMask(formatStr),
@@ -80,7 +80,7 @@ var Toolbar = /*#__PURE__*/React.forwardRef(function (props, ref) {
80
80
  return;
81
81
  }
82
82
 
83
- onClickShortcut === null || onClickShortcut === void 0 ? void 0 : onClickShortcut(value, closeOverlay !== null && closeOverlay !== void 0 ? closeOverlay : false, event);
83
+ onClickShortcut === null || onClickShortcut === void 0 ? void 0 : onClickShortcut(value, closeOverlay !== false ? true : false, event);
84
84
  };
85
85
 
86
86
  return /*#__PURE__*/React.createElement(Button, {
@@ -3,7 +3,7 @@ import { FormControlBaseProps, PickerBaseProps } from '../@types/common';
3
3
  import { PickerComponent, PickerToggleProps } from '../Picker';
4
4
  import { DisabledDateFunction, RangeType, DateRange } from './types';
5
5
  export interface DateRangePickerProps extends PickerBaseProps, FormControlBaseProps<DateRange | null>, Pick<PickerToggleProps, 'caretAs' | 'readOnly' | 'plaintext'> {
6
- /** Configure shortcut options */
6
+ /** Predefined date ranges */
7
7
  ranges?: RangeType[];
8
8
  /** Format date */
9
9
  format?: string;
@@ -135,11 +135,31 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
135
135
  */
136
136
 
137
137
  var updateCalendarDateRange = useCallback(function (value, calendarKey) {
138
+ var nextValue = value;
139
+ var shouldTime = DateUtils.shouldTime,
140
+ getHours = DateUtils.getHours,
141
+ getMinutes = DateUtils.getMinutes,
142
+ getSeconds = DateUtils.getSeconds,
143
+ set = DateUtils.set;
144
+
145
+ if (shouldTime(formatStr) && calendarKey === undefined && (value === null || value === void 0 ? void 0 : value.length) === 1 && (defaultCalendarValue === null || defaultCalendarValue === void 0 ? void 0 : defaultCalendarValue.length) === 2) {
146
+ var calendarEndDate = (calendarDate === null || calendarDate === void 0 ? void 0 : calendarDate[1]) || defaultCalendarValue[1];
147
+ var _startDate = value[0]; // When updating the start date, the time of the end date should keep the time set by the user by default.
148
+
149
+ var _endDate = set(addMonths(_startDate, 1), {
150
+ hours: getHours(calendarEndDate),
151
+ minutes: getMinutes(calendarEndDate),
152
+ seconds: getSeconds(calendarEndDate)
153
+ });
154
+
155
+ nextValue = [_startDate, _endDate];
156
+ }
157
+
138
158
  setCalendarDate(getCalendarDate({
139
- value: value,
159
+ value: nextValue,
140
160
  calendarKey: calendarKey
141
161
  }));
142
- }, []); // if valueProp changed then update selectValue/hoverValue
162
+ }, [calendarDate, defaultCalendarValue, formatStr]); // if valueProp changed then update selectValue/hoverValue
143
163
 
144
164
  useEffect(function () {
145
165
  setSelectedDates(valueProp !== null && valueProp !== void 0 ? valueProp : []);
@@ -435,10 +455,11 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
435
455
  var nextCalendarDate;
436
456
 
437
457
  if (value && value.length) {
438
- var _startDate = value[0],
458
+ var _startDate2 = value[0],
439
459
  endData = value[1];
440
- nextCalendarDate = [_startDate, isSameMonth(_startDate, endData) ? addMonths(endData, 1) : endData];
460
+ nextCalendarDate = [_startDate2, isSameMonth(_startDate2, endData) ? addMonths(endData, 1) : endData];
441
461
  } else {
462
+ // Reset the date on the calendar to the default date
442
463
  nextCalendarDate = getCalendarDate({
443
464
  value: defaultCalendarValue !== null && defaultCalendarValue !== void 0 ? defaultCalendarValue : null
444
465
  });
@@ -598,7 +619,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
598
619
  as: toggleAs,
599
620
  ref: targetRef,
600
621
  appearance: appearance,
601
- input: true,
622
+ editable: true,
602
623
  inputMask: DateUtils.getDateMask(rangeFormatStr),
603
624
  inputValue: value ? getDisplayString(value, true) : '',
604
625
  inputPlaceholder: typeof placeholder === 'string' && placeholder ? placeholder : rangeFormatStr,
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  import _isUndefined from "lodash/isUndefined";
4
- import React, { useRef, useEffect, useImperativeHandle, useCallback, useContext, useState } from 'react';
4
+ import React, { useRef, useEffect, useImperativeHandle, useCallback, useContext, useState, useMemo } from 'react';
5
5
  import get from 'lodash/get';
6
6
  import isNil from 'lodash/isNil';
7
7
  import contains from 'dom-lib/contains';
@@ -258,56 +258,65 @@ var OverlayTrigger = /*#__PURE__*/React.forwardRef(function (props, ref) {
258
258
  var preventDefault = useCallback(function (event) {
259
259
  event.preventDefault();
260
260
  }, []);
261
- var triggerEvents = {
262
- onClick: onClick,
263
- onContextMenu: onContextMenu,
264
- onMouseOver: onMouseOver,
265
- onMouseOut: onMouseOut,
266
- onFocus: onFocus,
267
- onBlur: onBlur,
268
- onMouseMove: onMouseMove
269
- };
261
+ var triggerEvents = useMemo(function () {
262
+ // Pass events by props
263
+ var events = {
264
+ onClick: onClick,
265
+ onContextMenu: onContextMenu,
266
+ onMouseOver: onMouseOver,
267
+ onMouseOut: onMouseOut,
268
+ onFocus: onFocus,
269
+ onBlur: onBlur,
270
+ onMouseMove: onMouseMove
271
+ }; // When trigger is disabled, no predefined event listeners are added.
272
+
273
+ if (disabled || readOnly || plaintext || trigger === 'none') {
274
+ return events;
275
+ } // Get the cursor position through onMouseMove.
276
+ // https://rsuitejs.com/components/tooltip/#follow-cursor
277
+
278
+
279
+ if (followCursor) {
280
+ events.onMouseMove = createChainedFunction(handledMoveOverlay, onMouseMove);
281
+ } // The `click` event is usually used in `toggle` scenarios.
282
+ // The first click will open and the second click will close.
283
+
270
284
 
271
- if (!disabled && !readOnly && !plaintext) {
272
285
  if (isOneOf('click', trigger)) {
273
- triggerEvents.onClick = createChainedFunction(handleOpenState, triggerEvents.onClick);
274
- }
286
+ events.onClick = createChainedFunction(handleOpenState, events.onClick);
287
+ return events;
288
+ } // The difference between it and the click event is that it does not trigger the close.
275
289
 
276
- if (isOneOf('contextMenu', trigger)) {
277
- triggerEvents.onContextMenu = createChainedFunction(preventDefault, handleOpenState, triggerEvents.onContextMenu);
278
- }
279
290
 
280
291
  if (isOneOf('active', trigger)) {
281
- triggerEvents.onClick = createChainedFunction(handleDelayedOpen, triggerEvents.onClick);
292
+ events.onClick = createChainedFunction(handleDelayedOpen, events.onClick);
293
+ return events;
282
294
  }
283
295
 
284
296
  if (isOneOf('hover', trigger)) {
285
- var onMouseOverListener = null;
286
- var onMouseOutListener = null;
287
-
288
- if (trigger !== 'none') {
289
- onMouseOverListener = function onMouseOverListener(e) {
290
- return onMouseEventHandler(handleDelayedOpen, e);
291
- };
297
+ var onMouseOverListener = function onMouseOverListener(e) {
298
+ return onMouseEventHandler(handleDelayedOpen, e);
299
+ };
292
300
 
293
- onMouseOutListener = function onMouseOutListener(e) {
294
- return onMouseEventHandler(handleDelayedClose, e);
295
- };
296
- }
301
+ var onMouseOutListener = function onMouseOutListener(e) {
302
+ return onMouseEventHandler(handleDelayedClose, e);
303
+ };
297
304
 
298
- triggerEvents.onMouseOver = createChainedFunction(onMouseOverListener, onMouseOver);
299
- triggerEvents.onMouseOut = createChainedFunction(onMouseOutListener, onMouseOut);
305
+ events.onMouseOver = createChainedFunction(onMouseOverListener, events.onMouseOver);
306
+ events.onMouseOut = createChainedFunction(onMouseOutListener, events.onMouseOut);
300
307
  }
301
308
 
302
309
  if (isOneOf('focus', trigger)) {
303
- triggerEvents.onFocus = createChainedFunction(handleDelayedOpen, onFocus);
304
- triggerEvents.onBlur = createChainedFunction(handleDelayedClose, onBlur);
310
+ events.onFocus = createChainedFunction(handleDelayedOpen, events.onFocus);
311
+ events.onBlur = createChainedFunction(handleDelayedClose, events.onBlur);
305
312
  }
306
313
 
307
- if (trigger !== 'none' && followCursor) {
308
- triggerEvents.onMouseMove = createChainedFunction(handledMoveOverlay, onMouseMove);
314
+ if (isOneOf('contextMenu', trigger)) {
315
+ events.onContextMenu = createChainedFunction(preventDefault, handleOpenState, events.onContextMenu);
309
316
  }
310
- }
317
+
318
+ return events;
319
+ }, [disabled, followCursor, handleDelayedClose, handleDelayedOpen, handleOpenState, handledMoveOverlay, onBlur, onClick, onContextMenu, onFocus, onMouseMove, onMouseOut, onMouseOver, plaintext, preventDefault, readOnly, trigger]);
311
320
 
312
321
  var renderOverlay = function renderOverlay() {
313
322
  var overlayProps = _extends({}, rest, {
@@ -19,7 +19,7 @@ export interface DropdownMenuProps<Multiple = false> extends StandardProps, Omit
19
19
  rowHeight?: number;
20
20
  rowGroupHeight?: number;
21
21
  virtualized?: boolean;
22
- listProps?: ListProps;
22
+ listProps?: Partial<ListProps>;
23
23
  /** Custom selected option */
24
24
  renderMenuItem?: (itemLabel: React.ReactNode, item: any) => React.ReactNode;
25
25
  renderMenuGroup?: (title: React.ReactNode, item: any) => React.ReactNode;
@@ -15,7 +15,7 @@ export interface PickerToggleProps extends ToggleButtonProps {
15
15
  readOnly?: boolean;
16
16
  plaintext?: boolean;
17
17
  tabIndex?: number;
18
- input?: boolean;
18
+ editable?: boolean;
19
19
  inputPlaceholder?: string;
20
20
  inputMask?: (string | RegExp)[];
21
21
  onInputChange?: (value: string, event: React.ChangeEvent) => void;
@@ -29,12 +29,12 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
29
29
  readOnly = props.readOnly,
30
30
  plaintext = props.plaintext,
31
31
  hasValue = props.hasValue,
32
+ editable = props.editable,
32
33
  cleanableProp = props.cleanable,
33
34
  _props$tabIndex = props.tabIndex,
34
- tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex,
35
+ tabIndexProp = _props$tabIndex === void 0 ? editable ? -1 : 0 : _props$tabIndex,
35
36
  id = props.id,
36
37
  value = props.value,
37
- input = props.input,
38
38
  inputPlaceholder = props.inputPlaceholder,
39
39
  inputValueProp = props.inputValue,
40
40
  _props$inputMask = props.inputMask,
@@ -52,9 +52,10 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
52
52
  _props$caretAs = props.caretAs,
53
53
  caretAs = _props$caretAs === void 0 ? caretComponent : _props$caretAs,
54
54
  label = props.label,
55
- rest = _objectWithoutPropertiesLoose(props, ["active", "as", "classPrefix", "children", "caret", "className", "disabled", "readOnly", "plaintext", "hasValue", "cleanable", "tabIndex", "id", "value", "input", "inputPlaceholder", "inputValue", "inputMask", "onInputChange", "onInputPressEnter", "onInputBlur", "onInputFocus", "onClean", "onFocus", "onBlur", "placement", "caretComponent", "caretAs", "label"]);
55
+ rest = _objectWithoutPropertiesLoose(props, ["active", "as", "classPrefix", "children", "caret", "className", "disabled", "readOnly", "plaintext", "hasValue", "editable", "cleanable", "tabIndex", "id", "value", "inputPlaceholder", "inputValue", "inputMask", "onInputChange", "onInputPressEnter", "onInputBlur", "onInputFocus", "onClean", "onFocus", "onBlur", "placement", "caretComponent", "caretAs", "label"]);
56
56
 
57
57
  var inputRef = useRef(null);
58
+ var comboboxRef = useRef(null);
58
59
 
59
60
  var _useState = useState(false),
60
61
  activeState = _useState[0],
@@ -74,30 +75,46 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
74
75
  setInputValue = _useState2[1];
75
76
 
76
77
  useEffect(function () {
77
- var value = getInputValue();
78
- setInputValue(value);
78
+ if (comboboxRef.current) {
79
+ var _value = getInputValue();
80
+
81
+ setInputValue(_value);
82
+ }
79
83
  }, [getInputValue]);
80
84
  var classes = merge(className, withClassPrefix({
81
85
  active: activeProp || activeState
82
86
  }));
83
87
  var handleFocus = useCallback(function (event) {
84
88
  setActive(true);
85
- onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
86
89
 
87
- if (input) {
88
- var _inputRef$current;
90
+ if (editable) {
91
+ // Avoid firing the onFocus event twice when DatePicker and DateRangePicker allow keyboard input.
92
+ if (event.target === inputRef.current) {
93
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
94
+ } // Force the input to be focused and editable.
89
95
 
90
- (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
96
+
97
+ if (document.activeElement === comboboxRef.current) {
98
+ var _inputRef$current;
99
+
100
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
101
+ }
102
+ } else {
103
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
91
104
  }
92
- }, [input, onFocus]);
105
+ }, [editable, onFocus]);
93
106
  var handleBlur = useCallback(function (event) {
94
- if (inputRef.current && document.activeElement !== inputRef.current) {
107
+ if (inputRef.current && !editable) {
108
+ setActive(false);
109
+ } // When activeElement is an input, it remains active.
110
+
111
+
112
+ if (editable && inputRef.current && document.activeElement !== inputRef.current) {
95
113
  setActive(false);
96
- inputRef.current.blur();
97
114
  }
98
115
 
99
116
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
100
- }, [onBlur]);
117
+ }, [editable, onBlur]);
101
118
 
102
119
  var handleInputBlur = function handleInputBlur(event) {
103
120
  setInputValue(getInputValue());
@@ -105,10 +122,13 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
105
122
  };
106
123
 
107
124
  var handleClean = useCallback(function (event) {
125
+ var _inputRef$current2, _comboboxRef$current;
126
+
108
127
  event.stopPropagation();
109
- onClean === null || onClean === void 0 ? void 0 : onClean(event);
110
- setActive(false);
111
- }, [onClean]);
128
+ onClean === null || onClean === void 0 ? void 0 : onClean(event); // When the value is cleared, the current component is still in focus.
129
+
130
+ editable ? (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus() : (_comboboxRef$current = comboboxRef.current) === null || _comboboxRef$current === void 0 ? void 0 : _comboboxRef$current.focus();
131
+ }, [editable, onClean]);
112
132
  var handleInputChange = useCallback(function (event) {
113
133
  var _event$target;
114
134
 
@@ -117,10 +137,18 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
117
137
  onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(value, event);
118
138
  }, [onInputChange]);
119
139
  var handleInputKeyDown = useCallback(function (event) {
120
- if (input && event.key === KEY_VALUES.ENTER) {
140
+ if (editable && event.key === KEY_VALUES.ENTER) {
121
141
  onInputPressEnter === null || onInputPressEnter === void 0 ? void 0 : onInputPressEnter(event);
122
142
  }
123
- }, [onInputPressEnter, input]);
143
+ }, [onInputPressEnter, editable]);
144
+ var renderInput = useCallback(function (ref, props) {
145
+ return /*#__PURE__*/React.createElement("input", _extends({
146
+ ref: mergeRefs(inputRef, ref),
147
+ style: {
148
+ pointerEvents: editable ? undefined : 'none'
149
+ }
150
+ }, props));
151
+ }, [editable]);
124
152
  var ToggleCaret = useToggleCaret(placement);
125
153
  var Caret = caretAs !== null && caretAs !== void 0 ? caretAs : ToggleCaret;
126
154
 
@@ -133,7 +161,8 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
133
161
 
134
162
  var showCleanButton = cleanableProp && hasValue && !readOnly; // When the component is read-only or disabled, the input is not interactive.
135
163
 
136
- var inputFocused = readOnly || disabled ? false : input && activeState;
164
+ var inputFocused = readOnly || disabled ? false : editable && activeState;
165
+ var tabIndex = disabled ? undefined : tabIndexProp;
137
166
  return /*#__PURE__*/React.createElement(Component, _extends({
138
167
  role: "combobox",
139
168
  "aria-haspopup": "listbox",
@@ -141,9 +170,9 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
141
170
  "aria-disabled": disabled,
142
171
  "aria-owns": id ? id + "-listbox" : undefined
143
172
  }, rest, {
144
- ref: ref,
173
+ ref: mergeRefs(comboboxRef, ref),
145
174
  disabled: disabled,
146
- tabIndex: disabled ? undefined : tabIndex,
175
+ tabIndex: tabIndex,
147
176
  className: classes,
148
177
  onFocus: !disabled ? handleFocus : null // The debounce is set to 200 to solve the flicker caused by the switch between input and div.
149
178
  ,
@@ -160,16 +189,12 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
160
189
  readOnly: !inputFocused,
161
190
  disabled: disabled,
162
191
  "aria-controls": id ? id + "-listbox" : undefined,
163
- tabIndex: -1,
192
+ tabIndex: editable ? 0 : -1,
164
193
  className: prefix('textbox', {
165
194
  'read-only': !inputFocused
166
195
  }),
167
196
  placeholder: inputPlaceholder,
168
- render: function render(ref, props) {
169
- return /*#__PURE__*/React.createElement("input", _extends({
170
- ref: mergeRefs(inputRef, ref)
171
- }, props));
172
- }
197
+ render: renderInput
173
198
  }), children ? /*#__PURE__*/React.createElement("span", {
174
199
  className: prefix(hasValue ? 'value' : 'placeholder'),
175
200
  "aria-placeholder": typeof children === 'string' ? children : undefined
@@ -1,8 +1,8 @@
1
1
  import React, { Ref } from 'react';
2
2
  import { PickerLocale } from '../locales';
3
3
  import { PickerInstance, PickerToggleProps } from '../Picker';
4
+ import { ListProps } from '../Picker/VirtualizedList';
4
5
  import { FormControlPickerProps, ItemDataType } from '../@types/common';
5
- import { ListProps } from 'react-virtualized/dist/commonjs/List';
6
6
  export interface SelectProps<T> {
7
7
  /** Set group condition key in data */
8
8
  groupBy?: string;
@@ -14,7 +14,7 @@ export interface SelectProps<T> {
14
14
  * List-related properties in `react-virtualized`
15
15
  * https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types
16
16
  */
17
- listProps?: ListProps;
17
+ listProps?: Partial<ListProps>;
18
18
  /** Custom search rules. */
19
19
  searchBy?: (keyword: string, label: React.ReactNode, item: ItemDataType) => boolean;
20
20
  /** Sort options */
@@ -85,4 +85,13 @@ React.createElement(SelectPicker, {
85
85
  return /*#__PURE__*/React.createElement("div", null);
86
86
  },
87
87
  data: []
88
+ }); // Override the default value of listProps.
89
+
90
+ /*#__PURE__*/
91
+ React.createElement(SelectPicker, {
92
+ data: [],
93
+ virtualized: true,
94
+ listProps: {
95
+ rowHeight: 70
96
+ }
88
97
  });
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { StandardProps, ItemDataType, RsRefForwardingComponent } from '../@types/common';
3
- import { ListProps } from 'react-virtualized/dist/commonjs/List';
3
+ import { ListProps } from '../Picker/VirtualizedList';
4
4
  /**
5
5
  * Tree Node Drag Type
6
6
  */
@@ -50,7 +50,7 @@ export interface TreeBaseProps<ValueType = string | number, ItemDataType = Recor
50
50
  * List-related properties in `react-virtualized`
51
51
  * https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types
52
52
  */
53
- listProps?: ListProps;
53
+ listProps?: Partial<ListProps>;
54
54
  /** Expand all nodes By default */
55
55
  defaultExpandAll?: boolean;
56
56
  /** searchKeyword (Controlled) */
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import Tree from '../Tree'; // Override the default value of listProps.
3
+
4
+ /*#__PURE__*/
5
+ React.createElement(Tree, {
6
+ data: [],
7
+ virtualized: true,
8
+ listProps: {
9
+ rowHeight: 70
10
+ }
11
+ });
@@ -35,6 +35,7 @@ export { default as startOfWeek } from 'date-fns/startOfWeek';
35
35
  export { default as subDays } from 'date-fns/subDays';
36
36
  export { default as isMatch } from 'date-fns/isMatch';
37
37
  export { default as isValid } from 'date-fns/isValid';
38
+ export { default as set } from 'date-fns/set';
38
39
  export declare type CalendarOnlyPropsType = 'disabledHours' | 'disabledMinutes' | 'disabledSeconds' | 'hideHours' | 'hideMinutes' | 'hideSeconds';
39
40
  export declare const calendarOnlyProps: CalendarOnlyPropsType[];
40
41
  /**
@@ -42,6 +42,7 @@ export { default as startOfWeek } from 'date-fns/startOfWeek';
42
42
  export { default as subDays } from 'date-fns/subDays';
43
43
  export { default as isMatch } from 'date-fns/isMatch';
44
44
  export { default as isValid } from 'date-fns/isValid';
45
+ export { default as set } from 'date-fns/set';
45
46
  var disabledTimeProps = ['disabledHours', 'disabledMinutes', 'disabledSeconds'];
46
47
  var hideTimeProps = ['hideHours', 'hideMinutes', 'hideSeconds'];
47
48
  export var calendarOnlyProps = disabledTimeProps.concat(hideTimeProps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.16.2",
3
+ "version": "5.16.5",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",