rsuite 5.17.0-beta → 5.17.0-beta.1
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 +6 -0
- package/Picker/styles/index.less +1 -1
- package/cjs/AutoComplete/AutoComplete.d.ts +3 -1
- package/cjs/AutoComplete/AutoComplete.js +6 -2
- package/cjs/AutoComplete/test/AutoComplete.test.d.ts +1 -0
- package/cjs/AutoComplete/test/AutoComplete.test.js +23 -0
- package/cjs/DatePicker/DatePicker.js +1 -1
- package/cjs/DateRangePicker/DateRangePicker.js +1 -1
- package/cjs/Disclosure/Disclosure.d.ts +2 -2
- package/cjs/Disclosure/Disclosure.js +6 -6
- package/cjs/Navbar/NavbarDropdownMenu.js +16 -10
- package/cjs/Overlay/OverlayTrigger.js +43 -34
- package/cjs/Picker/PickerToggle.d.ts +1 -1
- package/cjs/Picker/PickerToggle.js +52 -27
- package/cjs/utils/dateUtils.js +0 -0
- package/dist/rsuite-rtl.css +1 -1
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +1 -1
- package/dist/rsuite.js +7 -7
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/AutoComplete/AutoComplete.d.ts +3 -1
- package/esm/AutoComplete/AutoComplete.js +6 -2
- package/esm/AutoComplete/test/AutoComplete.test.d.ts +1 -0
- package/esm/AutoComplete/test/AutoComplete.test.js +18 -0
- package/esm/DatePicker/DatePicker.js +1 -1
- package/esm/DateRangePicker/DateRangePicker.js +1 -1
- package/esm/Disclosure/Disclosure.d.ts +2 -2
- package/esm/Disclosure/Disclosure.js +6 -6
- package/esm/Navbar/NavbarDropdownMenu.js +14 -8
- package/esm/Overlay/OverlayTrigger.js +44 -35
- package/esm/Picker/PickerToggle.d.ts +1 -1
- package/esm/Picker/PickerToggle.js +52 -27
- package/esm/utils/dateUtils.js +0 -0
- 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
|
+
});
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import DisclosureButton from './DisclosureButton';
|
|
3
3
|
import DisclosureContent from './DisclosureContent';
|
|
4
|
-
export declare type DisclosureTrigger = 'click' | '
|
|
5
|
-
export interface DisclosureRenderProps extends Pick<React.HTMLAttributes<HTMLElement>, '
|
|
4
|
+
export declare type DisclosureTrigger = 'click' | 'hover';
|
|
5
|
+
export interface DisclosureRenderProps extends Pick<React.HTMLAttributes<HTMLElement>, 'onMouseEnter' | 'onMouseLeave'> {
|
|
6
6
|
open: boolean;
|
|
7
7
|
}
|
|
8
8
|
export interface DisclosureProps {
|
|
@@ -59,7 +59,7 @@ var Disclosure = /*#__PURE__*/React.memo(function (props) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
var
|
|
62
|
+
var onMouseEnter = useCallback(function (event) {
|
|
63
63
|
if (!open) {
|
|
64
64
|
dispatch({
|
|
65
65
|
type: DisclosureActionTypes.Show
|
|
@@ -67,7 +67,7 @@ var Disclosure = /*#__PURE__*/React.memo(function (props) {
|
|
|
67
67
|
onToggle === null || onToggle === void 0 ? void 0 : onToggle(true, event);
|
|
68
68
|
}
|
|
69
69
|
}, [open, dispatch, onToggle]);
|
|
70
|
-
var
|
|
70
|
+
var onMouseLeave = useCallback(function (event) {
|
|
71
71
|
if (open) {
|
|
72
72
|
dispatch({
|
|
73
73
|
type: DisclosureActionTypes.Hide
|
|
@@ -98,13 +98,13 @@ var Disclosure = /*#__PURE__*/React.memo(function (props) {
|
|
|
98
98
|
open: open
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
if (trigger.includes('
|
|
102
|
-
renderProps.
|
|
103
|
-
renderProps.
|
|
101
|
+
if (trigger.includes('hover')) {
|
|
102
|
+
renderProps.onMouseEnter = onMouseEnter;
|
|
103
|
+
renderProps.onMouseLeave = onMouseLeave;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
return renderProps;
|
|
107
|
-
}, [open, trigger,
|
|
107
|
+
}, [open, trigger, onMouseEnter, onMouseLeave]);
|
|
108
108
|
return /*#__PURE__*/React.createElement(DisclosureContext.Provider, {
|
|
109
109
|
value: contextValue
|
|
110
110
|
}, children(renderProps, containerElementRef));
|
|
@@ -5,12 +5,12 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
5
5
|
var _templateObject, _templateObject2;
|
|
6
6
|
|
|
7
7
|
import React, { useContext } from 'react';
|
|
8
|
-
import omit from 'lodash/omit';
|
|
9
|
-
import { mergeRefs, useClassNames } from '../utils';
|
|
10
8
|
import PropTypes from 'prop-types';
|
|
9
|
+
import omit from 'lodash/omit';
|
|
10
|
+
import isNil from 'lodash/isNil';
|
|
11
11
|
import AngleLeft from '@rsuite/icons/legacy/AngleLeft';
|
|
12
12
|
import AngleRight from '@rsuite/icons/legacy/AngleRight';
|
|
13
|
-
import useCustom from '../utils
|
|
13
|
+
import { mergeRefs, useClassNames, useCustom } from '../utils';
|
|
14
14
|
import { NavbarContext } from '.';
|
|
15
15
|
import Disclosure from '../Disclosure';
|
|
16
16
|
import NavContext from '../Nav/NavContext';
|
|
@@ -73,7 +73,7 @@ var NavbarDropdownMenu = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
73
73
|
var Icon = rtl ? AngleLeft : AngleRight;
|
|
74
74
|
return /*#__PURE__*/React.createElement(Disclosure, {
|
|
75
75
|
hideOnClickOutside: true,
|
|
76
|
-
trigger: ['click', '
|
|
76
|
+
trigger: ['click', 'hover'],
|
|
77
77
|
onToggle: function onToggle(open, event) {
|
|
78
78
|
return _onToggle === null || _onToggle === void 0 ? void 0 : _onToggle(open, undefined, event);
|
|
79
79
|
}
|
|
@@ -98,12 +98,18 @@ var NavbarDropdownMenu = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
98
98
|
open: open,
|
|
99
99
|
disabled: disabled
|
|
100
100
|
}));
|
|
101
|
+
var dataAttributes = {
|
|
102
|
+
'data-event-key': eventKey
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if (!isNil(eventKey) && typeof eventKey !== 'string') {
|
|
106
|
+
dataAttributes['data-event-key-type'] = typeof eventKey;
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
102
110
|
ref: mergeRefs(buttonRef, buttonRef),
|
|
103
|
-
className: classes
|
|
104
|
-
|
|
105
|
-
"data-event-key-type": typeof eventKey
|
|
106
|
-
}, buttonProps), icon && /*#__PURE__*/React.cloneElement(icon, {
|
|
111
|
+
className: classes
|
|
112
|
+
}, dataAttributes, buttonProps), icon && /*#__PURE__*/React.cloneElement(icon, {
|
|
107
113
|
className: prefix('menu-icon')
|
|
108
114
|
}), title, /*#__PURE__*/React.createElement(Icon, {
|
|
109
115
|
className: prefix(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["toggle-icon"])))
|
|
@@ -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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
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
|
-
|
|
292
|
+
events.onClick = createChainedFunction(handleDelayedOpen, events.onClick);
|
|
293
|
+
return events;
|
|
282
294
|
}
|
|
283
295
|
|
|
284
296
|
if (isOneOf('hover', trigger)) {
|
|
285
|
-
var onMouseOverListener =
|
|
286
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
301
|
+
var onMouseOutListener = function onMouseOutListener(e) {
|
|
302
|
+
return onMouseEventHandler(handleDelayedClose, e);
|
|
303
|
+
};
|
|
297
304
|
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
304
|
-
|
|
310
|
+
events.onFocus = createChainedFunction(handleDelayedOpen, events.onFocus);
|
|
311
|
+
events.onBlur = createChainedFunction(handleDelayedClose, events.onBlur);
|
|
305
312
|
}
|
|
306
313
|
|
|
307
|
-
if (
|
|
308
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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", "
|
|
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
|
-
|
|
78
|
-
|
|
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 (
|
|
88
|
-
|
|
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
|
-
|
|
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
|
-
}, [
|
|
105
|
+
}, [editable, onFocus]);
|
|
93
106
|
var handleBlur = useCallback(function (event) {
|
|
94
|
-
if (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
|
-
|
|
111
|
-
|
|
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 (
|
|
140
|
+
if (editable && event.key === KEY_VALUES.ENTER) {
|
|
121
141
|
onInputPressEnter === null || onInputPressEnter === void 0 ? void 0 : onInputPressEnter(event);
|
|
122
142
|
}
|
|
123
|
-
}, [onInputPressEnter,
|
|
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 :
|
|
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:
|
|
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:
|
|
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/esm/utils/dateUtils.js
CHANGED
|
File without changes
|