rsuite 5.16.3 → 5.16.4

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.
@@ -437,7 +437,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
437
437
  as: toggleAs,
438
438
  ref: targetRef,
439
439
  appearance: appearance,
440
- input: true,
440
+ editable: true,
441
441
  inputValue: value ? formatDate(value, formatStr) : '',
442
442
  inputPlaceholder: typeof placeholder === 'string' && placeholder ? placeholder : formatStr,
443
443
  inputMask: DateUtils.getDateMask(formatStr),
@@ -598,7 +598,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
598
598
  as: toggleAs,
599
599
  ref: targetRef,
600
600
  appearance: appearance,
601
- input: true,
601
+ editable: true,
602
602
  inputMask: DateUtils.getDateMask(rangeFormatStr),
603
603
  inputValue: value ? getDisplayString(value, true) : '',
604
604
  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, {
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.16.3",
3
+ "version": "5.16.4",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",