@dxc-technology/halstack-react 6.1.0 → 6.2.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.
Files changed (41) hide show
  1. package/accordion/Accordion.js +122 -103
  2. package/accordion/Accordion.stories.tsx +1 -2
  3. package/accordion/Accordion.test.js +9 -10
  4. package/accordion/types.d.ts +3 -3
  5. package/accordion-group/AccordionGroup.js +1 -21
  6. package/accordion-group/AccordionGroup.stories.tsx +27 -1
  7. package/accordion-group/AccordionGroup.test.js +20 -45
  8. package/accordion-group/types.d.ts +8 -2
  9. package/alert/Alert.js +1 -1
  10. package/box/Box.js +1 -1
  11. package/checkbox/Checkbox.js +88 -95
  12. package/checkbox/Checkbox.test.js +93 -16
  13. package/checkbox/types.d.ts +2 -2
  14. package/common/variables.js +8 -4
  15. package/dropdown/Dropdown.js +1 -1
  16. package/footer/Footer.stories.tsx +8 -1
  17. package/header/Header.stories.tsx +4 -4
  18. package/layout/ApplicationLayout.stories.tsx +1 -0
  19. package/package.json +8 -8
  20. package/select/Listbox.js +0 -1
  21. package/slider/Slider.js +112 -91
  22. package/slider/Slider.stories.tsx +7 -1
  23. package/slider/Slider.test.js +87 -24
  24. package/slider/types.d.ts +2 -2
  25. package/switch/Switch.js +1 -1
  26. package/tabs/Tab.d.ts +4 -0
  27. package/tabs/Tab.js +135 -0
  28. package/tabs/Tabs.js +360 -104
  29. package/tabs/Tabs.stories.tsx +74 -0
  30. package/tabs/Tabs.test.js +217 -6
  31. package/tabs/types.d.ts +14 -4
  32. package/tag/Tag.js +1 -1
  33. package/text-input/Icons.d.ts +8 -0
  34. package/text-input/Icons.js +60 -0
  35. package/text-input/Suggestion.js +7 -5
  36. package/text-input/Suggestions.d.ts +4 -0
  37. package/text-input/Suggestions.js +134 -0
  38. package/text-input/TextInput.js +103 -201
  39. package/text-input/TextInput.stories.tsx +189 -181
  40. package/text-input/TextInput.test.js +163 -162
  41. package/text-input/types.d.ts +16 -2
@@ -27,66 +27,33 @@ var _variables = require("../common/variables.js");
27
27
 
28
28
  var _utils = require("../common/utils.js");
29
29
 
30
- var _uuid = require("uuid");
31
-
32
30
  var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
33
31
 
34
32
  var _NumberInputContext = _interopRequireDefault(require("../number-input/NumberInputContext"));
35
33
 
36
- var _Suggestion = _interopRequireDefault(require("./Suggestion"));
34
+ var _Suggestions = _interopRequireDefault(require("./Suggestions"));
35
+
36
+ var Popover = _interopRequireWildcard(require("@radix-ui/react-popover"));
37
37
 
38
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16;
38
+ var _Icons = _interopRequireDefault(require("./Icons"));
39
+
40
+ var _uuid = require("uuid");
41
+
42
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
39
43
 
40
44
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
41
45
 
42
46
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
43
47
 
44
- var textInputIcons = {
45
- error: /*#__PURE__*/_react["default"].createElement("svg", {
46
- xmlns: "http://www.w3.org/2000/svg",
47
- height: "24px",
48
- viewBox: "0 0 24 24",
49
- width: "24px",
50
- fill: "currentColor"
51
- }, /*#__PURE__*/_react["default"].createElement("path", {
52
- d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
53
- })),
54
- clear: /*#__PURE__*/_react["default"].createElement("svg", {
55
- xmlns: "http://www.w3.org/2000/svg",
56
- width: "24",
57
- height: "24",
58
- viewBox: "0 0 24 24",
59
- fill: "currentColor"
60
- }, /*#__PURE__*/_react["default"].createElement("path", {
61
- d: "M0 0h24v24H0V0z",
62
- fill: "none"
63
- }), /*#__PURE__*/_react["default"].createElement("path", {
64
- d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"
65
- })),
66
- increment: /*#__PURE__*/_react["default"].createElement("svg", {
67
- xmlns: "http://www.w3.org/2000/svg",
68
- height: "24px",
69
- viewBox: "0 0 24 24",
70
- width: "24px",
71
- fill: "currentColor"
72
- }, /*#__PURE__*/_react["default"].createElement("path", {
73
- d: "M0 0h24v24H0z",
74
- fill: "none"
75
- }), /*#__PURE__*/_react["default"].createElement("path", {
76
- d: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"
77
- })),
78
- decrement: /*#__PURE__*/_react["default"].createElement("svg", {
79
- xmlns: "http://www.w3.org/2000/svg",
80
- height: "24px",
81
- viewBox: "0 0 24 24",
82
- width: "24px",
83
- fill: "currentColor"
84
- }, /*#__PURE__*/_react["default"].createElement("path", {
85
- d: "M0 0h24v24H0z",
86
- fill: "none"
87
- }), /*#__PURE__*/_react["default"].createElement("path", {
88
- d: "M19 13H5v-2h14v2z"
89
- }))
48
+ var sizes = {
49
+ small: "240px",
50
+ medium: "360px",
51
+ large: "480px",
52
+ fillParent: "100%"
53
+ };
54
+
55
+ var calculateWidth = function calculateWidth(margin, size) {
56
+ return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
90
57
  };
91
58
 
92
59
  var makeCancelable = function makeCancelable(promise) {
@@ -110,21 +77,8 @@ var makeCancelable = function makeCancelable(promise) {
110
77
  };
111
78
  };
112
79
 
113
- var patternMatch = function patternMatch(pattern, value) {
114
- return new RegExp(pattern).test(value);
115
- };
116
-
117
- var getLastOptionIndex = function getLastOptionIndex(filteredSuggestions) {
118
- var last = 0;
119
-
120
- var reducer = function reducer(acc, current) {
121
- var _current$options;
122
-
123
- return acc + ((_current$options = current.options) === null || _current$options === void 0 ? void 0 : _current$options.length);
124
- };
125
-
126
- if (filteredSuggestions.length > 0) filteredSuggestions[0].options ? last = filteredSuggestions.reduce(reducer, 0) - 1 : last = filteredSuggestions.length - 1;
127
- return last;
80
+ var patternMissmatch = function patternMissmatch(pattern, value) {
81
+ return pattern && !new RegExp(pattern).test(value);
128
82
  };
129
83
 
130
84
  var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
@@ -162,53 +116,48 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
162
116
  size = _ref$size === void 0 ? "medium" : _ref$size,
163
117
  _ref$tabIndex = _ref.tabIndex,
164
118
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
119
+ var id = (0, _react.useState)((0, _uuid.v4)());
120
+ var inputId = "input-".concat(id);
121
+ var autosuggestId = "suggestions-".concat(id);
122
+ var errorId = "error-".concat(id);
165
123
 
166
- var _useState = (0, _react.useState)("input-".concat((0, _uuid.v4)())),
167
- _useState2 = (0, _slicedToArray2["default"])(_useState, 1),
168
- inputId = _useState2[0];
124
+ var _useState = (0, _react.useState)(defaultValue),
125
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
126
+ innerValue = _useState2[0],
127
+ setInnerValue = _useState2[1];
169
128
 
170
- var _useState3 = (0, _react.useState)(defaultValue),
129
+ var _useState3 = (0, _react.useState)(false),
171
130
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
172
- innerValue = _useState4[0],
173
- setInnerValue = _useState4[1];
131
+ isOpen = _useState4[0],
132
+ changeIsOpen = _useState4[1];
174
133
 
175
134
  var _useState5 = (0, _react.useState)(false),
176
135
  _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
177
- isOpen = _useState6[0],
178
- changeIsOpen = _useState6[1];
136
+ isSearching = _useState6[0],
137
+ changeIsSearching = _useState6[1];
179
138
 
180
139
  var _useState7 = (0, _react.useState)(false),
181
140
  _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
182
- isSearching = _useState8[0],
183
- changeIsSearching = _useState8[1];
141
+ isAutosuggestError = _useState8[0],
142
+ changeIsAutosuggestError = _useState8[1];
184
143
 
185
- var _useState9 = (0, _react.useState)(false),
144
+ var _useState9 = (0, _react.useState)([]),
186
145
  _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
187
- isAutosuggestError = _useState10[0],
188
- changeIsAutosuggestError = _useState10[1];
146
+ filteredSuggestions = _useState10[0],
147
+ changeFilteredSuggestions = _useState10[1];
189
148
 
190
- var _useState11 = (0, _react.useState)([]),
149
+ var _useState11 = (0, _react.useState)(-1),
191
150
  _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
192
- filteredSuggestions = _useState12[0],
193
- changeFilteredSuggestions = _useState12[1];
151
+ visualFocusIndex = _useState12[0],
152
+ changeVisualFocusIndex = _useState12[1];
194
153
 
195
- var _useState13 = (0, _react.useState)(-1),
196
- _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
197
- visualFocusedSuggIndex = _useState14[0],
198
- changeVisualFocusedSuggIndex = _useState14[1];
199
-
200
- var suggestionsRef = (0, _react.useRef)(null);
154
+ var inputContainerRef = (0, _react.useRef)(null);
201
155
  var inputRef = (0, _react.useRef)(null);
202
156
  var actionRef = (0, _react.useRef)(null);
203
157
  var colorsTheme = (0, _useTheme["default"])();
204
158
  var translatedLabels = (0, _useTranslatedLabels["default"])();
205
159
  var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
206
- var autosuggestId = "".concat(inputId, "-listBox");
207
- var errorId = "error-".concat(inputId);
208
160
  var numberInputContext = (0, _react.useContext)(_NumberInputContext["default"]);
209
- var lastOptionIndex = (0, _react.useMemo)(function () {
210
- return getLastOptionIndex(filteredSuggestions);
211
- }, [filteredSuggestions]);
212
161
 
213
162
  var isNotOptional = function isNotOptional(value) {
214
163
  return value === "" && !optional;
@@ -241,8 +190,10 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
241
190
  };
242
191
 
243
192
  var closeSuggestions = function closeSuggestions() {
244
- changeIsOpen(false);
245
- changeVisualFocusedSuggIndex(-1);
193
+ if (hasSuggestions()) {
194
+ changeIsOpen(false);
195
+ changeVisualFocusIndex(-1);
196
+ }
246
197
  };
247
198
 
248
199
  var changeValue = function changeValue(newValue) {
@@ -254,10 +205,10 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
254
205
  });else if (isLengthIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
255
206
  value: changedValue,
256
207
  error: translatedLabels.formFields.lengthErrorMessage(minLength, maxLength)
257
- });else if (newValue && pattern && !patternMatch(pattern, newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
208
+ });else if (patternMissmatch(pattern, newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
258
209
  value: changedValue,
259
210
  error: translatedLabels.formFields.formatRequestedErrorMessage
260
- });else if (newValue && isNumberIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
211
+ });else if (isNumberIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
261
212
  value: changedValue,
262
213
  error: getNumberErrorMessage(newValue)
263
214
  });else onChange === null || onChange === void 0 ? void 0 : onChange({
@@ -280,17 +231,17 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
280
231
  };
281
232
 
282
233
  var handleIOnBlur = function handleIOnBlur(event) {
283
- suggestions && closeSuggestions();
234
+ closeSuggestions();
284
235
  if (isNotOptional(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
285
236
  value: event.target.value,
286
237
  error: translatedLabels.formFields.requiredValueErrorMessage
287
238
  });else if (isLengthIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
288
239
  value: event.target.value,
289
240
  error: translatedLabels.formFields.lengthErrorMessage(minLength, maxLength)
290
- });else if (event.target.value && pattern && !patternMatch(pattern, event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
241
+ });else if (patternMissmatch(pattern, event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
291
242
  value: event.target.value,
292
243
  error: translatedLabels.formFields.formatRequestedErrorMessage
293
- });else if (event.target.value && isNumberIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
244
+ });else if (isNumberIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
294
245
  value: event.target.value,
295
246
  error: getNumberErrorMessage(event.target.value)
296
247
  });else onBlur === null || onBlur === void 0 ? void 0 : onBlur({
@@ -310,7 +261,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
310
261
  openSuggestions();
311
262
 
312
263
  if (!isAutosuggestError && !isSearching && filteredSuggestions.length > 0) {
313
- changeVisualFocusedSuggIndex(function (visualFocusedSuggIndex) {
264
+ changeVisualFocusIndex(function (visualFocusedSuggIndex) {
314
265
  if (visualFocusedSuggIndex < filteredSuggestions.length - 1) return visualFocusedSuggIndex + 1;else if (visualFocusedSuggIndex === filteredSuggestions.length - 1) return 0;
315
266
  });
316
267
  }
@@ -328,7 +279,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
328
279
  openSuggestions();
329
280
 
330
281
  if (!isAutosuggestError && !isSearching && filteredSuggestions.length > 0) {
331
- changeVisualFocusedSuggIndex(function (visualFocusedSuggIndex) {
282
+ changeVisualFocusIndex(function (visualFocusedSuggIndex) {
332
283
  if (visualFocusedSuggIndex === 0 || visualFocusedSuggIndex === -1) return filteredSuggestions.length > 0 ? filteredSuggestions.length - 1 : suggestions.length - 1;else return visualFocusedSuggIndex - 1;
333
284
  });
334
285
  }
@@ -349,8 +300,8 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
349
300
 
350
301
  case "Enter":
351
302
  if (hasSuggestions() && !isSearching) {
352
- var validFocusedSuggestion = filteredSuggestions.length > 0 && visualFocusedSuggIndex >= 0 && visualFocusedSuggIndex < filteredSuggestions.length;
353
- validFocusedSuggestion && changeValue(filteredSuggestions[visualFocusedSuggIndex]);
303
+ var validFocusedSuggestion = filteredSuggestions.length > 0 && visualFocusIndex >= 0 && visualFocusIndex < filteredSuggestions.length;
304
+ validFocusedSuggestion && changeValue(filteredSuggestions[visualFocusIndex]);
354
305
  isOpen && closeSuggestions();
355
306
  }
356
307
 
@@ -423,15 +374,12 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
423
374
  }
424
375
  };
425
376
 
426
- (0, _react.useLayoutEffect)(function () {
427
- var _suggestionsRef$curre, _visualFocusedOptionE;
377
+ var getTextInputWidth = (0, _react.useCallback)(function () {
378
+ var _inputContainerRef$cu;
428
379
 
429
- var visualFocusedOptionEl = suggestionsRef === null || suggestionsRef === void 0 ? void 0 : (_suggestionsRef$curre = suggestionsRef.current) === null || _suggestionsRef$curre === void 0 ? void 0 : _suggestionsRef$curre.querySelectorAll("[role='option']")[visualFocusedSuggIndex];
430
- visualFocusedOptionEl === null || visualFocusedOptionEl === void 0 ? void 0 : (_visualFocusedOptionE = visualFocusedOptionEl.scrollIntoView) === null || _visualFocusedOptionE === void 0 ? void 0 : _visualFocusedOptionE.call(visualFocusedOptionEl, {
431
- block: "nearest",
432
- inline: "start"
433
- });
434
- }, [visualFocusedSuggIndex]);
380
+ var rect = inputContainerRef === null || inputContainerRef === void 0 ? void 0 : (_inputContainerRef$cu = inputContainerRef.current) === null || _inputContainerRef$cu === void 0 ? void 0 : _inputContainerRef$cu.getBoundingClientRect();
381
+ return rect === null || rect === void 0 ? void 0 : rect.width;
382
+ }, []);
435
383
  (0, _react.useEffect)(function () {
436
384
  if (typeof suggestions === "function") {
437
385
  changeIsSearching(true);
@@ -455,7 +403,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
455
403
  changeFilteredSuggestions(suggestions.filter(function (suggestion) {
456
404
  return suggestion.toUpperCase().startsWith((value !== null && value !== void 0 ? value : innerValue).toUpperCase());
457
405
  }));
458
- changeVisualFocusedSuggIndex(-1);
406
+ changeVisualFocusIndex(-1);
459
407
  }
460
408
 
461
409
  (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" && setNumberProps(numberInputContext.typeNumber, numberInputContext.minNumber, numberInputContext.maxNumber, numberInputContext.stepNumber);
@@ -474,12 +422,17 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
474
422
  }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
475
423
  disabled: disabled,
476
424
  backgroundType: backgroundType
477
- }, helperText), /*#__PURE__*/_react["default"].createElement(InputContainer, {
425
+ }, helperText), /*#__PURE__*/_react["default"].createElement(Popover.Root, {
426
+ open: isOpen && (filteredSuggestions.length > 0 || isSearching || isAutosuggestError)
427
+ }, /*#__PURE__*/_react["default"].createElement(Popover.Trigger, {
428
+ asChild: true
429
+ }, /*#__PURE__*/_react["default"].createElement(InputContainer, {
478
430
  error: error ? true : false,
479
431
  disabled: disabled,
480
432
  backgroundType: backgroundType,
481
433
  onClick: handleInputContainerOnClick,
482
- onMouseDown: handleInputContainerOnMouseDown
434
+ onMouseDown: handleInputContainerOnMouseDown,
435
+ ref: inputContainerRef
483
436
  }, prefix && /*#__PURE__*/_react["default"].createElement(Prefix, {
484
437
  disabled: disabled,
485
438
  backgroundType: backgroundType
@@ -490,9 +443,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
490
443
  placeholder: placeholder,
491
444
  onBlur: handleIOnBlur,
492
445
  onChange: handleIOnChange,
493
- onFocus: function onFocus() {
494
- openSuggestions();
495
- },
446
+ onFocus: openSuggestions,
496
447
  onKeyDown: handleIOnKeyDown,
497
448
  onMouseDown: function onMouseDown(event) {
498
449
  event.stopPropagation();
@@ -503,24 +454,22 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
503
454
  pattern: pattern,
504
455
  minLength: minLength,
505
456
  maxLength: maxLength,
506
- autoComplete: autocomplete,
457
+ autoComplete: autocomplete === "off" ? "nope" : autocomplete,
507
458
  tabIndex: tabIndex,
508
459
  role: isTextInputType() && hasSuggestions() ? "combobox" : "textbox",
509
460
  "aria-autocomplete": isTextInputType() && hasSuggestions() ? "list" : undefined,
510
461
  "aria-controls": isTextInputType() && hasSuggestions() ? autosuggestId : undefined,
511
462
  "aria-disabled": disabled,
512
- "aria-expanded": isTextInputType() && hasSuggestions() ? isOpen ? "true" : "false" : undefined,
513
- "aria-activedescendant": isTextInputType() && hasSuggestions() && isOpen && visualFocusedSuggIndex !== -1 ? "suggestion-".concat(visualFocusedSuggIndex) : undefined,
514
- "aria-invalid": error ? "true" : "false",
463
+ "aria-expanded": isTextInputType() && hasSuggestions() ? isOpen : undefined,
464
+ "aria-activedescendant": isTextInputType() && hasSuggestions() && isOpen && visualFocusIndex !== -1 ? "suggestion-".concat(visualFocusIndex) : undefined,
465
+ "aria-invalid": error ? true : false,
515
466
  "aria-errormessage": error ? errorId : undefined,
516
- "aria-required": optional ? "false" : "true"
467
+ "aria-required": optional ? false : true
517
468
  }), !disabled && error && /*#__PURE__*/_react["default"].createElement(ErrorIcon, {
518
469
  backgroundType: backgroundType,
519
470
  "aria-label": "Error"
520
- }, textInputIcons.error), !disabled && clearable && (value !== null && value !== void 0 ? value : innerValue).length > 0 && /*#__PURE__*/_react["default"].createElement(Action, {
521
- onClick: function onClick() {
522
- return handleClearActionOnClick();
523
- },
471
+ }, _Icons["default"].error), !disabled && clearable && (value !== null && value !== void 0 ? value : innerValue).length > 0 && /*#__PURE__*/_react["default"].createElement(Action, {
472
+ onClick: handleClearActionOnClick,
524
473
  onMouseDown: function onMouseDown(event) {
525
474
  event.stopPropagation();
526
475
  },
@@ -528,12 +477,10 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
528
477
  tabIndex: tabIndex,
529
478
  title: translatedLabels.textInput.clearFieldActionTitle,
530
479
  "aria-label": translatedLabels.textInput.clearFieldActionTitle
531
- }, textInputIcons.clear), (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Action, {
480
+ }, _Icons["default"].clear), (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Action, {
532
481
  ref: actionRef,
533
482
  disabled: disabled,
534
- onClick: function onClick() {
535
- return handleDecrementActionOnClick();
536
- },
483
+ onClick: handleDecrementActionOnClick,
537
484
  onMouseDown: function onMouseDown(event) {
538
485
  event.stopPropagation();
539
486
  },
@@ -541,12 +488,10 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
541
488
  tabIndex: tabIndex,
542
489
  title: translatedLabels.numberInput.decrementValueTitle,
543
490
  "aria-label": translatedLabels.numberInput.decrementValueTitle
544
- }, textInputIcons.decrement), /*#__PURE__*/_react["default"].createElement(Action, {
491
+ }, _Icons["default"].decrement), /*#__PURE__*/_react["default"].createElement(Action, {
545
492
  ref: actionRef,
546
493
  disabled: disabled,
547
- onClick: function onClick() {
548
- return handleIncrementActionOnClick();
549
- },
494
+ onClick: handleIncrementActionOnClick,
550
495
  onMouseDown: function onMouseDown(event) {
551
496
  event.stopPropagation();
552
497
  },
@@ -554,12 +499,10 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
554
499
  tabIndex: tabIndex,
555
500
  title: translatedLabels.numberInput.incrementValueTitle,
556
501
  "aria-label": translatedLabels.numberInput.incrementValueTitle
557
- }, textInputIcons.increment)) : action && /*#__PURE__*/_react["default"].createElement(Action, {
502
+ }, _Icons["default"].increment)), action && /*#__PURE__*/_react["default"].createElement(Action, {
558
503
  ref: actionRef,
559
504
  disabled: disabled,
560
- onClick: function onClick() {
561
- return action.onClick();
562
- },
505
+ onClick: action.onClick,
563
506
  onMouseDown: function onMouseDown(event) {
564
507
  event.stopPropagation();
565
508
  },
@@ -572,49 +515,36 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref
572
515
  }) : action.icon), suffix && /*#__PURE__*/_react["default"].createElement(Suffix, {
573
516
  disabled: disabled,
574
517
  backgroundType: backgroundType
575
- }, suffix), isOpen && (filteredSuggestions.length > 0 || isSearching || isAutosuggestError) && /*#__PURE__*/_react["default"].createElement(Suggestions, {
576
- id: autosuggestId,
577
- error: isAutosuggestError ? true : false,
578
- onMouseDown: function onMouseDown(event) {
518
+ }, suffix))), /*#__PURE__*/_react["default"].createElement(Popover.Content, {
519
+ sideOffset: 4,
520
+ onOpenAutoFocus: function onOpenAutoFocus(event) {
521
+ // Avoid select to lose focus when the list is opened
579
522
  event.preventDefault();
580
523
  },
581
- ref: suggestionsRef,
582
- role: "listbox",
583
- "aria-label": label
584
- }, !isSearching && !isAutosuggestError && filteredSuggestions.length > 0 && filteredSuggestions.map(function (suggestion, index) {
585
- return /*#__PURE__*/_react["default"].createElement(_Suggestion["default"], {
586
- key: "suggestion-".concat(index),
587
- id: "suggestion-".concat(index),
588
- value: value !== null && value !== void 0 ? value : innerValue,
589
- onClick: function onClick() {
590
- changeValue(suggestion);
591
- closeSuggestions();
592
- },
593
- suggestion: suggestion,
594
- isLast: index === lastOptionIndex,
595
- visuallyFocused: visualFocusedSuggIndex === index,
596
- highlighted: typeof suggestions === "function"
597
- });
598
- }), isSearching && /*#__PURE__*/_react["default"].createElement(SuggestionsSystemMessage, null, translatedLabels.textInput.searchingMessage), isAutosuggestError && /*#__PURE__*/_react["default"].createElement(SuggestionsError, null, /*#__PURE__*/_react["default"].createElement(SuggestionsErrorIcon, {
599
- backgroundType: backgroundType
600
- }, textInputIcons.error), translatedLabels.textInput.fetchingDataErrorMessage))), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
524
+ onCloseAutoFocus: function onCloseAutoFocus(event) {
525
+ // Avoid select to lose focus when the list is closed
526
+ event.preventDefault();
527
+ }
528
+ }, /*#__PURE__*/_react["default"].createElement(_Suggestions["default"], {
529
+ id: autosuggestId,
530
+ value: value !== null && value !== void 0 ? value : innerValue,
531
+ suggestions: filteredSuggestions,
532
+ visualFocusIndex: visualFocusIndex,
533
+ highlightedSuggestions: typeof suggestions !== "function",
534
+ searchHasErrors: isAutosuggestError,
535
+ isSearching: isSearching,
536
+ suggestionOnClick: function suggestionOnClick(suggestion) {
537
+ changeValue(suggestion);
538
+ closeSuggestions();
539
+ },
540
+ getTextInputWidth: getTextInputWidth
541
+ }))), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
601
542
  id: errorId,
602
543
  backgroundType: backgroundType,
603
544
  "aria-live": error ? "assertive" : "off"
604
545
  }, error)));
605
546
  });
606
547
 
607
- var sizes = {
608
- small: "240px",
609
- medium: "360px",
610
- large: "480px",
611
- fillParent: "100%"
612
- };
613
-
614
- var calculateWidth = function calculateWidth(margin, size) {
615
- return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
616
- };
617
-
618
548
  var TextInputContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n\n width: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
619
549
  return calculateWidth(props.margin, props.size);
620
550
  }, function (props) {
@@ -729,33 +659,5 @@ var Error = _styledComponents["default"].span(_templateObject12 || (_templateObj
729
659
  return props.theme.fontFamily;
730
660
  });
731
661
 
732
- var Suggestions = _styledComponents["default"].ul(_templateObject13 || (_templateObject13 = (0, _taggedTemplateLiteral2["default"])(["\n position: absolute;\n z-index: 1;\n max-height: 304px;\n overflow-y: auto;\n top: calc(100% + 4px);\n left: 0;\n margin: 0;\n padding: 0.25rem 0;\n width: 100%;\n background-color: ", ";\n border: 1px solid\n ", ";\n border-radius: 0.25rem;\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);\n cursor: default;\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"])), function (props) {
733
- return props.error ? props.theme.errorListDialogBackgroundColor : props.theme.listDialogBackgroundColor;
734
- }, function (props) {
735
- return props.error ? props.theme.errorListDialogBorderColor : props.theme.listDialogBorderColor;
736
- }, function (props) {
737
- return props.theme.listOptionFontColor;
738
- }, function (props) {
739
- return props.theme.fontFamily;
740
- }, function (props) {
741
- return props.theme.listOptionFontSize;
742
- }, function (props) {
743
- return props.theme.listOptionFontStyle;
744
- }, function (props) {
745
- return props.theme.listOptionFontWeight;
746
- });
747
-
748
- var SuggestionsSystemMessage = _styledComponents["default"].span(_templateObject14 || (_templateObject14 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n padding: 0.25rem 1rem;\n color: ", ";\n line-height: 1.715em;\n"])), function (props) {
749
- return props.theme.systemMessageFontColor;
750
- });
751
-
752
- var SuggestionsErrorIcon = _styledComponents["default"].span(_templateObject15 || (_templateObject15 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n margin-right: 0.5rem;\n height: 18px;\n width: 18px;\n color: ", ";\n"])), function (props) {
753
- return props.backgroundType === "dark" ? props.theme.errorIconColorOnDark : props.theme.errorIconColor;
754
- });
755
-
756
- var SuggestionsError = _styledComponents["default"].span(_templateObject16 || (_templateObject16 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n padding: 0.25rem 1rem;\n align-items: center;\n line-height: 1.715em;\n color: ", ";\n"])), function (props) {
757
- return props.theme.errorListDialogFontColor;
758
- });
759
-
760
662
  var _default = DxcTextInput;
761
663
  exports["default"] = _default;