rsuite 5.16.4 → 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.
@@ -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
 
@@ -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
  */
@@ -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
  });
@@ -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.4",
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",