carbon-react 142.11.5 → 142.11.6

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.
@@ -10,7 +10,6 @@ import StyledDateInput from "./date.style";
10
10
  import Textbox from "../textbox";
11
11
  import DatePicker from "./__internal__/date-picker";
12
12
  import DateRangeContext from "../date-range/__internal__/date-range.context";
13
- import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
14
13
  import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
15
14
  import guid from "../../__internal__/utils/helpers/guid";
16
15
  const DateInput = /*#__PURE__*/React.forwardRef(({
@@ -48,6 +47,7 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
48
47
  const alreadyFocused = useRef(false);
49
48
  const isBlurBlocked = useRef(false);
50
49
  const focusedViaPicker = useRef(false);
50
+ const blockClose = useRef(false);
51
51
  const locale = useLocale();
52
52
  const {
53
53
  dateFnsLocale
@@ -89,17 +89,30 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
89
89
  };
90
90
  return customEvent;
91
91
  };
92
- const handleClickAway = () => {
93
- if (open) {
94
- alreadyFocused.current = true;
95
- internalInputRef.current?.focus();
96
- isBlurBlocked.current = false;
97
- internalInputRef.current?.blur();
98
- setOpen(false);
99
- alreadyFocused.current = false;
100
- }
101
- };
102
- const handleClickInside = useClickAwayListener(handleClickAway, "mousedown");
92
+
93
+ // Add custom listener to prevent issues with regards to double calls within the Date component
94
+ // This is a temporary fix until the Date component is refactored more info can be found:
95
+ // TODO: FE-6757
96
+ useEffect(() => {
97
+ const handleClick = () => {
98
+ if (!blockClose.current) {
99
+ if (open) {
100
+ alreadyFocused.current = true;
101
+ internalInputRef.current?.focus();
102
+ isBlurBlocked.current = false;
103
+ internalInputRef.current?.blur();
104
+ setOpen(false);
105
+ alreadyFocused.current = false;
106
+ }
107
+ } else {
108
+ blockClose.current = false;
109
+ }
110
+ };
111
+ document.addEventListener("mousedown", handleClick);
112
+ return function cleanup() {
113
+ document.removeEventListener("mousedown", handleClick);
114
+ };
115
+ }, [open]);
103
116
  const handleChange = ev => {
104
117
  isInitialValue.current = false;
105
118
  onChange(buildCustomEvent(ev));
@@ -165,7 +178,9 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
165
178
  }
166
179
  isBlurBlocked.current = false;
167
180
  if (!open && !alreadyFocused.current) {
168
- setOpen(true);
181
+ setTimeout(() => {
182
+ setOpen(true);
183
+ }, 0);
169
184
  } else {
170
185
  alreadyFocused.current = false;
171
186
  }
@@ -200,7 +215,7 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
200
215
  }
201
216
  };
202
217
  const handleMouseDown = ev => {
203
- handleClickInside();
218
+ blockClose.current = true;
204
219
  if (setInputRefMap) {
205
220
  isBlurBlocked.current = true;
206
221
  }
@@ -209,9 +224,13 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
209
224
  } = ev.target;
210
225
  if (type !== "text") {
211
226
  alreadyFocused.current = true;
212
- setOpen(prev => !prev);
227
+ setTimeout(() => {
228
+ setOpen(prev => !prev);
229
+ }, 0);
213
230
  } else if (!open) {
214
- setOpen(true);
231
+ setTimeout(() => {
232
+ setOpen(true);
233
+ }, 0);
215
234
  }
216
235
  };
217
236
  const handleIconMouseDown = ev => {
@@ -220,7 +239,7 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
220
239
  };
221
240
  const handlePickerMouseDown = () => {
222
241
  isBlurBlocked.current = true;
223
- handleClickInside();
242
+ blockClose.current = true;
224
243
  };
225
244
  const assignInput = useCallback(inputElement => {
226
245
  internalInputRef.current = inputElement;
@@ -15,7 +15,6 @@ var _date = _interopRequireDefault(require("./date.style"));
15
15
  var _textbox = _interopRequireDefault(require("../textbox"));
16
16
  var _datePicker = _interopRequireDefault(require("./__internal__/date-picker"));
17
17
  var _dateRange = _interopRequireDefault(require("../date-range/__internal__/date-range.context"));
18
- var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__internal__/useClickAwayListener"));
19
18
  var _useFormSpacing = _interopRequireDefault(require("../../hooks/__internal__/useFormSpacing"));
20
19
  var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/guid"));
21
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -57,6 +56,7 @@ const DateInput = exports.DateInput = /*#__PURE__*/_react.default.forwardRef(({
57
56
  const alreadyFocused = (0, _react.useRef)(false);
58
57
  const isBlurBlocked = (0, _react.useRef)(false);
59
58
  const focusedViaPicker = (0, _react.useRef)(false);
59
+ const blockClose = (0, _react.useRef)(false);
60
60
  const locale = (0, _useLocale.default)();
61
61
  const {
62
62
  dateFnsLocale
@@ -98,17 +98,30 @@ const DateInput = exports.DateInput = /*#__PURE__*/_react.default.forwardRef(({
98
98
  };
99
99
  return customEvent;
100
100
  };
101
- const handleClickAway = () => {
102
- if (open) {
103
- alreadyFocused.current = true;
104
- internalInputRef.current?.focus();
105
- isBlurBlocked.current = false;
106
- internalInputRef.current?.blur();
107
- setOpen(false);
108
- alreadyFocused.current = false;
109
- }
110
- };
111
- const handleClickInside = (0, _useClickAwayListener.default)(handleClickAway, "mousedown");
101
+
102
+ // Add custom listener to prevent issues with regards to double calls within the Date component
103
+ // This is a temporary fix until the Date component is refactored more info can be found:
104
+ // TODO: FE-6757
105
+ (0, _react.useEffect)(() => {
106
+ const handleClick = () => {
107
+ if (!blockClose.current) {
108
+ if (open) {
109
+ alreadyFocused.current = true;
110
+ internalInputRef.current?.focus();
111
+ isBlurBlocked.current = false;
112
+ internalInputRef.current?.blur();
113
+ setOpen(false);
114
+ alreadyFocused.current = false;
115
+ }
116
+ } else {
117
+ blockClose.current = false;
118
+ }
119
+ };
120
+ document.addEventListener("mousedown", handleClick);
121
+ return function cleanup() {
122
+ document.removeEventListener("mousedown", handleClick);
123
+ };
124
+ }, [open]);
112
125
  const handleChange = ev => {
113
126
  isInitialValue.current = false;
114
127
  onChange(buildCustomEvent(ev));
@@ -174,7 +187,9 @@ const DateInput = exports.DateInput = /*#__PURE__*/_react.default.forwardRef(({
174
187
  }
175
188
  isBlurBlocked.current = false;
176
189
  if (!open && !alreadyFocused.current) {
177
- setOpen(true);
190
+ setTimeout(() => {
191
+ setOpen(true);
192
+ }, 0);
178
193
  } else {
179
194
  alreadyFocused.current = false;
180
195
  }
@@ -209,7 +224,7 @@ const DateInput = exports.DateInput = /*#__PURE__*/_react.default.forwardRef(({
209
224
  }
210
225
  };
211
226
  const handleMouseDown = ev => {
212
- handleClickInside();
227
+ blockClose.current = true;
213
228
  if (setInputRefMap) {
214
229
  isBlurBlocked.current = true;
215
230
  }
@@ -218,9 +233,13 @@ const DateInput = exports.DateInput = /*#__PURE__*/_react.default.forwardRef(({
218
233
  } = ev.target;
219
234
  if (type !== "text") {
220
235
  alreadyFocused.current = true;
221
- setOpen(prev => !prev);
236
+ setTimeout(() => {
237
+ setOpen(prev => !prev);
238
+ }, 0);
222
239
  } else if (!open) {
223
- setOpen(true);
240
+ setTimeout(() => {
241
+ setOpen(true);
242
+ }, 0);
224
243
  }
225
244
  };
226
245
  const handleIconMouseDown = ev => {
@@ -229,7 +248,7 @@ const DateInput = exports.DateInput = /*#__PURE__*/_react.default.forwardRef(({
229
248
  };
230
249
  const handlePickerMouseDown = () => {
231
250
  isBlurBlocked.current = true;
232
- handleClickInside();
251
+ blockClose.current = true;
233
252
  };
234
253
  const assignInput = (0, _react.useCallback)(inputElement => {
235
254
  internalInputRef.current = inputElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "142.11.5",
3
+ "version": "142.11.6",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",