@datarobot/design-system 28.2.2 → 28.3.0
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/cjs/inline-edit/inline-edit.js +13 -12
- package/esm/inline-edit/inline-edit.js +14 -13
- package/js/bundle/bundle.js +13 -12
- package/js/bundle/bundle.min.js +1 -1
- package/package.json +1 -1
|
@@ -79,18 +79,7 @@ function InlineEdit({
|
|
|
79
79
|
const [touched, setTouched] = (0, _react.useState)(false);
|
|
80
80
|
const [inputValue, setInputValue] = (0, _react.useState)(value);
|
|
81
81
|
const [componentId] = (0, _react.useState)(() => (0, _uniqueId.default)());
|
|
82
|
-
|
|
83
|
-
// check if 2 elements have autofocus and render in same time
|
|
84
|
-
const [isEditMode, setIsEditMode] = (0, _react.useState)(() => {
|
|
85
|
-
if (isSomeOneOpen() || readOnly || isLoading) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (autoFocus) {
|
|
89
|
-
openState.set(componentId, true);
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
});
|
|
82
|
+
const [isEditMode, setIsEditMode] = (0, _react.useState)(false);
|
|
94
83
|
const container = (0, _react.useRef)(null);
|
|
95
84
|
const handleCancel = () => {
|
|
96
85
|
setInputValue(value);
|
|
@@ -119,6 +108,18 @@ function InlineEdit({
|
|
|
119
108
|
(0, _react.useEffect)(() => () => {
|
|
120
109
|
openState.delete(componentId);
|
|
121
110
|
}, []);
|
|
111
|
+
(0, _react.useLayoutEffect)(() => {
|
|
112
|
+
// If the component is mounted, autoFocus is true, and there are no other inline edits in edit mode -
|
|
113
|
+
// set the open state and edit mode to true
|
|
114
|
+
// previously it was set in state initialization function but since react 18 that initialization function
|
|
115
|
+
// can be called twice without unmount if 2+ components rendering inline edit are wrapped in Suspense and lazy loaded
|
|
116
|
+
// it results in inline edits being locked up because first id is set to true, however latest render would use different id
|
|
117
|
+
// it turns out to be common react thing: https://stackoverflow.com/questions/73325723/suspense-as-a-root-element-causes-two-instances-of-component-in-production-and
|
|
118
|
+
if (autoFocus && !(isSomeOneOpen() || readOnly || isLoading)) {
|
|
119
|
+
openState.set(componentId, true);
|
|
120
|
+
setIsEditMode(true);
|
|
121
|
+
}
|
|
122
|
+
}, []);
|
|
122
123
|
const onTextClick = e => {
|
|
123
124
|
e.preventDefault();
|
|
124
125
|
if (!isSomeOneOpen() && !readOnly && !isLoading) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect, useMemo, useRef } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useMemo, useRef, useLayoutEffect } from 'react';
|
|
2
2
|
import cls from 'classnames';
|
|
3
3
|
import uniqueId from 'lodash-es/uniqueId';
|
|
4
4
|
import { faPen } from '@fortawesome/free-solid-svg-icons/faPen';
|
|
@@ -71,18 +71,7 @@ export default function InlineEdit({
|
|
|
71
71
|
const [touched, setTouched] = useState(false);
|
|
72
72
|
const [inputValue, setInputValue] = useState(value);
|
|
73
73
|
const [componentId] = useState(() => uniqueId());
|
|
74
|
-
|
|
75
|
-
// check if 2 elements have autofocus and render in same time
|
|
76
|
-
const [isEditMode, setIsEditMode] = useState(() => {
|
|
77
|
-
if (isSomeOneOpen() || readOnly || isLoading) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
if (autoFocus) {
|
|
81
|
-
openState.set(componentId, true);
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
});
|
|
74
|
+
const [isEditMode, setIsEditMode] = useState(false);
|
|
86
75
|
const container = useRef(null);
|
|
87
76
|
const handleCancel = () => {
|
|
88
77
|
setInputValue(value);
|
|
@@ -111,6 +100,18 @@ export default function InlineEdit({
|
|
|
111
100
|
useEffect(() => () => {
|
|
112
101
|
openState.delete(componentId);
|
|
113
102
|
}, []);
|
|
103
|
+
useLayoutEffect(() => {
|
|
104
|
+
// If the component is mounted, autoFocus is true, and there are no other inline edits in edit mode -
|
|
105
|
+
// set the open state and edit mode to true
|
|
106
|
+
// previously it was set in state initialization function but since react 18 that initialization function
|
|
107
|
+
// can be called twice without unmount if 2+ components rendering inline edit are wrapped in Suspense and lazy loaded
|
|
108
|
+
// it results in inline edits being locked up because first id is set to true, however latest render would use different id
|
|
109
|
+
// it turns out to be common react thing: https://stackoverflow.com/questions/73325723/suspense-as-a-root-element-causes-two-instances-of-component-in-production-and
|
|
110
|
+
if (autoFocus && !(isSomeOneOpen() || readOnly || isLoading)) {
|
|
111
|
+
openState.set(componentId, true);
|
|
112
|
+
setIsEditMode(true);
|
|
113
|
+
}
|
|
114
|
+
}, []);
|
|
114
115
|
const onTextClick = e => {
|
|
115
116
|
e.preventDefault();
|
|
116
117
|
if (!isSomeOneOpen() && !readOnly && !isLoading) {
|
package/js/bundle/bundle.js
CHANGED
|
@@ -64526,18 +64526,7 @@ function InlineEdit(_ref) {
|
|
|
64526
64526
|
}),
|
|
64527
64527
|
_useState6 = _slicedToArray(_useState5, 1),
|
|
64528
64528
|
componentId = _useState6[0];
|
|
64529
|
-
|
|
64530
|
-
// check if 2 elements have autofocus and render in same time
|
|
64531
|
-
var _useState7 = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(function () {
|
|
64532
|
-
if (isSomeOneOpen() || readOnly || isLoading) {
|
|
64533
|
-
return false;
|
|
64534
|
-
}
|
|
64535
|
-
if (autoFocus) {
|
|
64536
|
-
openState.set(componentId, true);
|
|
64537
|
-
return true;
|
|
64538
|
-
}
|
|
64539
|
-
return false;
|
|
64540
|
-
}),
|
|
64529
|
+
var _useState7 = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false),
|
|
64541
64530
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
64542
64531
|
isEditMode = _useState8[0],
|
|
64543
64532
|
setIsEditMode = _useState8[1];
|
|
@@ -64574,6 +64563,18 @@ function InlineEdit(_ref) {
|
|
|
64574
64563
|
openState["delete"](componentId);
|
|
64575
64564
|
};
|
|
64576
64565
|
}, []);
|
|
64566
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useLayoutEffect)(function () {
|
|
64567
|
+
// If the component is mounted, autoFocus is true, and there are no other inline edits in edit mode -
|
|
64568
|
+
// set the open state and edit mode to true
|
|
64569
|
+
// previously it was set in state initialization function but since react 18 that initialization function
|
|
64570
|
+
// can be called twice without unmount if 2+ components rendering inline edit are wrapped in Suspense and lazy loaded
|
|
64571
|
+
// it results in inline edits being locked up because first id is set to true, however latest render would use different id
|
|
64572
|
+
// it turns out to be common react thing: https://stackoverflow.com/questions/73325723/suspense-as-a-root-element-causes-two-instances-of-component-in-production-and
|
|
64573
|
+
if (autoFocus && !(isSomeOneOpen() || readOnly || isLoading)) {
|
|
64574
|
+
openState.set(componentId, true);
|
|
64575
|
+
setIsEditMode(true);
|
|
64576
|
+
}
|
|
64577
|
+
}, []);
|
|
64577
64578
|
var onTextClick = function onTextClick(e) {
|
|
64578
64579
|
e.preventDefault();
|
|
64579
64580
|
if (!isSomeOneOpen() && !readOnly && !isLoading) {
|