rsuite 5.16.1 → 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.
Files changed (95) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/Picker/styles/index.less +3 -1
  3. package/Slider/styles/index.less +2 -1
  4. package/TreePicker/styles/index.less +0 -3
  5. package/cjs/Cascader/utils.js +3 -5
  6. package/cjs/CheckPicker/CheckPicker.d.ts +1 -1
  7. package/cjs/CheckPicker/test/CheckPicker.test.js +8 -0
  8. package/cjs/CheckTreePicker/CheckTreePicker.d.ts +2 -2
  9. package/cjs/CheckTreePicker/CheckTreePicker.js +5 -0
  10. package/cjs/CheckTreePicker/test/CheckTreePicker.test.d.ts +1 -0
  11. package/cjs/CheckTreePicker/test/CheckTreePicker.test.js +15 -0
  12. package/cjs/CheckTreePicker/utils.js +3 -1
  13. package/cjs/CustomProvider/CustomProvider.js +6 -3
  14. package/cjs/DatePicker/DatePicker.d.ts +1 -1
  15. package/cjs/DatePicker/DatePicker.js +1 -1
  16. package/cjs/DatePicker/Toolbar.js +1 -1
  17. package/cjs/DateRangePicker/Calendar.d.ts +0 -1
  18. package/cjs/DateRangePicker/Calendar.js +1 -39
  19. package/cjs/DateRangePicker/DateRangePicker.d.ts +1 -1
  20. package/cjs/DateRangePicker/DateRangePicker.js +23 -23
  21. package/cjs/DateRangePicker/utils.d.ts +2 -1
  22. package/cjs/DateRangePicker/utils.js +12 -3
  23. package/cjs/InputPicker/InputPicker.d.ts +2 -2
  24. package/cjs/InputPicker/test/InputPicker.test.d.ts +1 -0
  25. package/cjs/InputPicker/test/InputPicker.test.js +15 -0
  26. package/cjs/MultiCascader/utils.js +3 -2
  27. package/cjs/Overlay/OverlayTrigger.js +43 -34
  28. package/cjs/Panel/Panel.js +8 -7
  29. package/cjs/Picker/DropdownMenu.d.ts +1 -1
  30. package/cjs/Picker/PickerToggle.d.ts +1 -1
  31. package/cjs/Picker/PickerToggle.js +52 -27
  32. package/cjs/SelectPicker/SelectPicker.d.ts +9 -3
  33. package/cjs/SelectPicker/test/SelectPicker.test.js +33 -0
  34. package/cjs/Tree/Tree.d.ts +2 -2
  35. package/cjs/Tree/test/Tree.test.d.ts +1 -0
  36. package/cjs/Tree/test/Tree.test.js +18 -0
  37. package/cjs/TreePicker/TreePicker.d.ts +2 -2
  38. package/cjs/TreePicker/test/TreePicker.test.d.ts +1 -0
  39. package/cjs/TreePicker/test/TreePicker.test.js +15 -0
  40. package/cjs/utils/attachParent.d.ts +1 -0
  41. package/cjs/utils/attachParent.js +15 -0
  42. package/cjs/utils/treeUtils.js +3 -2
  43. package/cjs/utils/usePortal.d.ts +4 -2
  44. package/cjs/utils/usePortal.js +40 -14
  45. package/dist/rsuite-rtl.css +9 -10
  46. package/dist/rsuite-rtl.min.css +1 -1
  47. package/dist/rsuite-rtl.min.css.map +1 -1
  48. package/dist/rsuite.css +9 -10
  49. package/dist/rsuite.js +29 -18
  50. package/dist/rsuite.js.map +1 -1
  51. package/dist/rsuite.min.css +1 -1
  52. package/dist/rsuite.min.css.map +1 -1
  53. package/dist/rsuite.min.js +1 -1
  54. package/dist/rsuite.min.js.map +1 -1
  55. package/esm/Cascader/utils.js +2 -4
  56. package/esm/CheckPicker/CheckPicker.d.ts +1 -1
  57. package/esm/CheckPicker/test/CheckPicker.test.js +8 -0
  58. package/esm/CheckTreePicker/CheckTreePicker.d.ts +2 -2
  59. package/esm/CheckTreePicker/CheckTreePicker.js +5 -0
  60. package/esm/CheckTreePicker/test/CheckTreePicker.test.d.ts +1 -0
  61. package/esm/CheckTreePicker/test/CheckTreePicker.test.js +10 -0
  62. package/esm/CheckTreePicker/utils.js +2 -1
  63. package/esm/CustomProvider/CustomProvider.js +6 -3
  64. package/esm/DatePicker/DatePicker.d.ts +1 -1
  65. package/esm/DatePicker/DatePicker.js +1 -1
  66. package/esm/DatePicker/Toolbar.js +1 -1
  67. package/esm/DateRangePicker/Calendar.d.ts +0 -1
  68. package/esm/DateRangePicker/Calendar.js +2 -41
  69. package/esm/DateRangePicker/DateRangePicker.d.ts +1 -1
  70. package/esm/DateRangePicker/DateRangePicker.js +23 -23
  71. package/esm/DateRangePicker/utils.d.ts +2 -1
  72. package/esm/DateRangePicker/utils.js +12 -3
  73. package/esm/InputPicker/InputPicker.d.ts +2 -2
  74. package/esm/InputPicker/test/InputPicker.test.d.ts +1 -0
  75. package/esm/InputPicker/test/InputPicker.test.js +10 -0
  76. package/esm/MultiCascader/utils.js +2 -2
  77. package/esm/Overlay/OverlayTrigger.js +44 -35
  78. package/esm/Panel/Panel.js +8 -7
  79. package/esm/Picker/DropdownMenu.d.ts +1 -1
  80. package/esm/Picker/PickerToggle.d.ts +1 -1
  81. package/esm/Picker/PickerToggle.js +52 -27
  82. package/esm/SelectPicker/SelectPicker.d.ts +9 -3
  83. package/esm/SelectPicker/test/SelectPicker.test.js +32 -0
  84. package/esm/Tree/Tree.d.ts +2 -2
  85. package/esm/Tree/test/Tree.test.d.ts +1 -0
  86. package/esm/Tree/test/Tree.test.js +11 -0
  87. package/esm/TreePicker/TreePicker.d.ts +2 -2
  88. package/esm/TreePicker/test/TreePicker.test.d.ts +1 -0
  89. package/esm/TreePicker/test/TreePicker.test.js +10 -0
  90. package/esm/utils/attachParent.d.ts +1 -0
  91. package/esm/utils/attachParent.js +10 -0
  92. package/esm/utils/treeUtils.js +2 -2
  93. package/esm/utils/usePortal.d.ts +4 -2
  94. package/esm/utils/usePortal.js +36 -14
  95. package/package.json +1 -1
@@ -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 */
@@ -40,7 +40,13 @@ export interface MultipleSelectProps<T> extends Omit<SelectProps<T>, 'renderValu
40
40
  /** Custom render selected items */
41
41
  renderValue?: (value: T[], item: ItemDataType<T>[], selectedElement: React.ReactNode) => React.ReactNode;
42
42
  }
43
- export interface SelectPickerProps<T> extends FormControlPickerProps<T, PickerLocale, ItemDataType<T>>, SelectProps<T>, Pick<PickerToggleProps, 'label'> {
43
+ export interface SelectPickerProps<T> extends Omit<FormControlPickerProps<T, PickerLocale, ItemDataType<T>>, 'value' | 'defaultValue' | 'onChange'>, SelectProps<T>, Pick<PickerToggleProps, 'caretAs' | 'label'> {
44
+ /** Initial value */
45
+ defaultValue?: T;
46
+ /** Current value of the component. Creates a controlled component */
47
+ value?: T | null;
48
+ /** Called after the value has been changed */
49
+ onChange?: (value: T | null, event: React.SyntheticEvent) => void;
44
50
  }
45
51
  export interface SelectPickerComponent {
46
52
  <T>(props: SelectPickerProps<T> & {
@@ -62,4 +62,36 @@ React.createElement(SelectPicker, {
62
62
  React.createElement(SelectPicker, {
63
63
  label: "User",
64
64
  data: []
65
+ });
66
+
67
+ /*#__PURE__*/
68
+ React.createElement(SelectPicker, {
69
+ data: [{
70
+ label: 'Ascending',
71
+ value: 'asc'
72
+ }, {
73
+ label: 'Descending',
74
+ value: 'desc'
75
+ }],
76
+ value: "asc",
77
+ onChange: function onChange(value) {
78
+ expectType(value);
79
+ }
80
+ });
81
+
82
+ /*#__PURE__*/
83
+ React.createElement(SelectPicker, {
84
+ caretAs: function caretAs() {
85
+ return /*#__PURE__*/React.createElement("div", null);
86
+ },
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
+ }
65
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
+ });
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import { PickerLocale } from '../locales';
3
- import { PickerComponent } from '../Picker';
3
+ import { PickerComponent, PickerToggleProps } from '../Picker';
4
4
  import { TreeDragProps, TreeBaseProps } from '../Tree/Tree';
5
5
  import { FormControlPickerProps, ItemDataType } from '../@types/common';
6
6
  export declare const maxTreeHeight = 320;
7
- export interface TreePickerProps<T = number | string> extends TreeBaseProps<T, ItemDataType>, TreeDragProps, FormControlPickerProps<T, PickerLocale, ItemDataType> {
7
+ export interface TreePickerProps<T = number | string> extends TreeBaseProps<T, ItemDataType>, TreeDragProps, FormControlPickerProps<T, PickerLocale, ItemDataType>, Pick<PickerToggleProps, 'caretAs'> {
8
8
  /** The height of Dropdown */
9
9
  height?: number;
10
10
  /** Tree node cascade */
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import TreePicker from '../TreePicker';
3
+
4
+ /*#__PURE__*/
5
+ React.createElement(TreePicker, {
6
+ caretAs: function caretAs() {
7
+ return /*#__PURE__*/React.createElement("div", null);
8
+ },
9
+ data: []
10
+ });
@@ -0,0 +1 @@
1
+ export declare function attachParent<T>(data: T, parent: T): T;
@@ -0,0 +1,10 @@
1
+ export function attachParent(data, parent) {
2
+ // mark "parent" unenumable
3
+ Object.defineProperty(data, 'parent', {
4
+ value: parent,
5
+ writable: false,
6
+ enumerable: false,
7
+ configurable: true
8
+ });
9
+ return data;
10
+ }
@@ -13,6 +13,7 @@ import { TREE_NODE_DROP_POSITION, shallowEqual } from '../utils';
13
13
  import { shouldDisplay } from '../Picker';
14
14
  import reactToString from './reactToString';
15
15
  import { TREE_NODE_PADDING, TREE_NODE_ROOT_PADDING } from './constants';
16
+ import { attachParent } from './attachParent';
16
17
  // gap of tree node
17
18
  var TREE_NODE_GAP = 4;
18
19
  /**
@@ -59,8 +60,7 @@ export function flattenTree(tree, childrenKey, executor) {
59
60
 
60
61
  data.forEach(function (item, index) {
61
62
  var node = typeof executor === 'function' ? executor(item, index) : item;
62
- node.parent = parent;
63
- flattenData.push(_extends({}, node));
63
+ flattenData.push(attachParent(node, parent));
64
64
 
65
65
  if (item[childrenKey]) {
66
66
  traverse(item[childrenKey], item);
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
2
  interface PortalProps {
3
- id?: string;
4
3
  container?: HTMLElement | (() => HTMLElement | null) | null;
4
+ waitMount?: boolean;
5
5
  }
6
6
  declare function usePortal(props?: PortalProps): {
7
7
  target: HTMLElement | null;
8
- Portal: React.FC<any>;
8
+ Portal: ((props: any) => JSX.Element) | (({ children }: {
9
+ children: React.ReactNode;
10
+ }) => React.ReactPortal | null);
9
11
  };
10
12
  export default usePortal;
@@ -1,6 +1,25 @@
1
- import { useRef, useEffect, useCallback } from 'react';
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import React, { useRef, useEffect, useState, useCallback } from 'react';
2
3
  import { createPortal } from 'react-dom';
3
4
  import canUseDOM from 'dom-lib/canUseDOM';
5
+ var MountedPortal = /*#__PURE__*/React.memo(function (_ref) {
6
+ var children = _ref.children,
7
+ container = _ref.container;
8
+
9
+ var _useState = useState(false),
10
+ mounted = _useState[0],
11
+ setMounted = _useState[1];
12
+
13
+ useEffect(function () {
14
+ return setMounted(true);
15
+ }, []);
16
+
17
+ if (container && mounted) {
18
+ return /*#__PURE__*/createPortal(children, container);
19
+ }
20
+
21
+ return null;
22
+ });
4
23
 
5
24
  function usePortal(props) {
6
25
  if (props === void 0) {
@@ -8,25 +27,28 @@ function usePortal(props) {
8
27
  }
9
28
 
10
29
  var _props = props,
11
- id = _props.id,
12
- container = _props.container;
30
+ container = _props.container,
31
+ _props$waitMount = _props.waitMount,
32
+ waitMount = _props$waitMount === void 0 ? false : _props$waitMount;
13
33
  var rootElemRef = useRef(canUseDOM ? document.body : null);
14
34
  useEffect(function () {
15
- var containerElement = typeof container === 'function' ? container() : container; // Look for existing target dom element to append to
16
-
17
- var existingParent = id && document.querySelector("#" + id); // Parent is either a new root or the existing dom element
35
+ var containerElement = typeof container === 'function' ? container() : container; // Parent is either a new root or the existing dom element
18
36
 
19
- var parentElement = containerElement || existingParent || document.body;
37
+ var parentElement = containerElement || document.body;
20
38
  rootElemRef.current = parentElement;
21
- }, [rootElemRef, container, id]);
22
- var Portal = useCallback(function (_ref) {
23
- var children = _ref.children;
24
- if (rootElemRef.current != null) return /*#__PURE__*/createPortal(children, rootElemRef.current);
25
- return null;
26
- }, [rootElemRef]);
39
+ }, [rootElemRef, container]);
40
+ var Portal = useCallback(function (_ref2) {
41
+ var children = _ref2.children;
42
+ return rootElemRef.current != null ? /*#__PURE__*/createPortal(children, rootElemRef.current) : null;
43
+ }, []);
44
+ var WaitMountPortal = useCallback(function (props) {
45
+ return /*#__PURE__*/React.createElement(MountedPortal, _extends({
46
+ container: rootElemRef.current
47
+ }, props));
48
+ }, []);
27
49
  return {
28
50
  target: rootElemRef.current,
29
- Portal: Portal
51
+ Portal: waitMount ? WaitMountPortal : Portal
30
52
  };
31
53
  }
32
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.16.1",
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",