@dxc-technology/halstack-react 5.0.0 → 6.0.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 (128) hide show
  1. package/HalstackContext.d.ts +4 -2
  2. package/HalstackContext.js +110 -58
  3. package/accordion/Accordion.stories.tsx +1 -1
  4. package/accordion-group/AccordionGroup.js +1 -0
  5. package/alert/Alert.js +4 -1
  6. package/badge/Badge.d.ts +1 -1
  7. package/badge/Badge.js +5 -3
  8. package/badge/types.d.ts +1 -0
  9. package/bleed/Bleed.js +1 -34
  10. package/bleed/Bleed.stories.tsx +94 -95
  11. package/bleed/types.d.ts +1 -1
  12. package/box/Box.js +22 -32
  13. package/bulleted-list/BulletedList.d.ts +7 -0
  14. package/bulleted-list/BulletedList.js +123 -0
  15. package/bulleted-list/BulletedList.stories.tsx +200 -0
  16. package/bulleted-list/types.d.ts +11 -0
  17. package/{list → bulleted-list}/types.js +0 -0
  18. package/button/Button.js +3 -1
  19. package/card/Card.js +34 -36
  20. package/checkbox/Checkbox.js +4 -1
  21. package/common/variables.js +211 -88
  22. package/date-input/DateInput.js +5 -2
  23. package/dropdown/Dropdown.stories.tsx +1 -1
  24. package/file-input/FileInput.js +9 -6
  25. package/file-input/FileItem.js +7 -5
  26. package/flex/Flex.d.ts +4 -0
  27. package/flex/Flex.js +57 -0
  28. package/flex/Flex.stories.tsx +103 -0
  29. package/flex/types.d.ts +21 -0
  30. package/{radio → flex}/types.js +0 -0
  31. package/footer/Footer.js +7 -5
  32. package/footer/Icons.js +1 -1
  33. package/header/Header.js +7 -4
  34. package/inset/Inset.js +1 -34
  35. package/inset/Inset.stories.tsx +36 -36
  36. package/inset/types.d.ts +1 -1
  37. package/layout/ApplicationLayout.d.ts +16 -6
  38. package/layout/ApplicationLayout.js +70 -117
  39. package/layout/ApplicationLayout.stories.tsx +83 -93
  40. package/layout/Icons.d.ts +5 -0
  41. package/layout/Icons.js +13 -2
  42. package/layout/SidenavContext.d.ts +5 -0
  43. package/layout/SidenavContext.js +19 -0
  44. package/layout/types.d.ts +18 -33
  45. package/link/Link.d.ts +3 -2
  46. package/link/Link.js +57 -70
  47. package/link/Link.stories.tsx +88 -53
  48. package/link/Link.test.js +7 -15
  49. package/link/types.d.ts +7 -23
  50. package/main.d.ts +7 -10
  51. package/main.js +38 -56
  52. package/number-input/types.d.ts +1 -1
  53. package/package.json +3 -1
  54. package/paginator/Paginator.js +17 -38
  55. package/paginator/Paginator.test.js +42 -0
  56. package/paragraph/Paragraph.d.ts +6 -0
  57. package/paragraph/Paragraph.js +38 -0
  58. package/paragraph/Paragraph.stories.tsx +44 -0
  59. package/password-input/PasswordInput.js +7 -4
  60. package/password-input/PasswordInput.test.js +1 -2
  61. package/password-input/types.d.ts +1 -1
  62. package/progress-bar/ProgressBar.js +1 -1
  63. package/progress-bar/ProgressBar.stories.jsx +11 -11
  64. package/quick-nav/QuickNav.js +74 -20
  65. package/quick-nav/QuickNav.stories.tsx +43 -16
  66. package/quick-nav/types.d.ts +4 -4
  67. package/radio-group/Radio.js +1 -1
  68. package/radio-group/RadioGroup.js +10 -7
  69. package/resultsetTable/ResultsetTable.test.js +42 -0
  70. package/select/Listbox.d.ts +1 -1
  71. package/select/Listbox.js +35 -8
  72. package/select/Select.js +83 -78
  73. package/select/Select.stories.tsx +144 -100
  74. package/select/Select.test.js +299 -194
  75. package/select/types.d.ts +3 -4
  76. package/sidenav/Sidenav.d.ts +6 -5
  77. package/sidenav/Sidenav.js +172 -52
  78. package/sidenav/Sidenav.stories.tsx +154 -156
  79. package/sidenav/Sidenav.test.js +25 -37
  80. package/sidenav/types.d.ts +50 -27
  81. package/spinner/Spinner.js +1 -1
  82. package/switch/Switch.js +4 -1
  83. package/tabs/Tabs.stories.tsx +0 -6
  84. package/tabs-nav/NavTabs.d.ts +8 -0
  85. package/tabs-nav/NavTabs.js +125 -0
  86. package/tabs-nav/NavTabs.stories.tsx +170 -0
  87. package/tabs-nav/NavTabs.test.js +82 -0
  88. package/tabs-nav/Tab.d.ts +4 -0
  89. package/tabs-nav/Tab.js +132 -0
  90. package/tabs-nav/types.d.ts +53 -0
  91. package/{row → tabs-nav}/types.js +0 -0
  92. package/text-input/Suggestion.d.ts +4 -0
  93. package/text-input/Suggestion.js +55 -0
  94. package/text-input/TextInput.js +46 -72
  95. package/text-input/TextInput.test.js +1 -1
  96. package/text-input/types.d.ts +14 -2
  97. package/textarea/Textarea.js +10 -19
  98. package/textarea/types.d.ts +1 -1
  99. package/typography/Typography.d.ts +4 -0
  100. package/typography/Typography.js +131 -0
  101. package/typography/Typography.stories.tsx +198 -0
  102. package/typography/types.d.ts +18 -0
  103. package/{stack → typography}/types.js +0 -0
  104. package/useTranslatedLabels.d.ts +2 -0
  105. package/useTranslatedLabels.js +20 -0
  106. package/wizard/Wizard.js +36 -41
  107. package/wizard/Wizard.stories.tsx +20 -1
  108. package/wizard/types.d.ts +4 -3
  109. package/list/List.d.ts +0 -4
  110. package/list/List.js +0 -47
  111. package/list/List.stories.tsx +0 -95
  112. package/list/types.d.ts +0 -7
  113. package/radio/Radio.d.ts +0 -4
  114. package/radio/Radio.js +0 -173
  115. package/radio/Radio.stories.tsx +0 -192
  116. package/radio/Radio.test.js +0 -71
  117. package/radio/types.d.ts +0 -54
  118. package/row/Row.d.ts +0 -3
  119. package/row/Row.js +0 -127
  120. package/row/Row.stories.tsx +0 -237
  121. package/row/types.d.ts +0 -28
  122. package/stack/Stack.d.ts +0 -3
  123. package/stack/Stack.js +0 -97
  124. package/stack/Stack.stories.tsx +0 -164
  125. package/stack/types.d.ts +0 -24
  126. package/text/Text.d.ts +0 -7
  127. package/text/Text.js +0 -30
  128. package/text/Text.stories.tsx +0 -19
package/select/Select.js CHANGED
@@ -23,6 +23,8 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
23
23
 
24
24
  var _useTheme = _interopRequireDefault(require("../useTheme"));
25
25
 
26
+ var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
27
+
26
28
  var _variables = require("../common/variables.js");
27
29
 
28
30
  var _uuid = require("uuid");
@@ -33,16 +35,14 @@ var _Icons = _interopRequireDefault(require("./Icons"));
33
35
 
34
36
  var _Listbox = _interopRequireDefault(require("./Listbox"));
35
37
 
38
+ var Popover = _interopRequireWildcard(require("@radix-ui/react-popover"));
39
+
36
40
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
37
41
 
38
42
  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); }
39
43
 
40
44
  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; }
41
45
 
42
- var getNotOptionalErrorMessage = function getNotOptionalErrorMessage() {
43
- return "This field is required. Please, enter a value.";
44
- };
45
-
46
46
  var groupsHaveOptions = function groupsHaveOptions(innerOptions) {
47
47
  return innerOptions[0].hasOwnProperty("options") ? innerOptions[0].options ? innerOptions.some(function (groupOption) {
48
48
  return groupOption.options.length > 0;
@@ -57,6 +57,10 @@ var filteredGroupsHaveOptions = function filteredGroupsHaveOptions(filteredOptio
57
57
  }) : true;
58
58
  };
59
59
 
60
+ var canOpenOptions = function canOpenOptions(options, disabled) {
61
+ return !disabled && (options === null || options === void 0 ? void 0 : options.length) > 0 && groupsHaveOptions(options);
62
+ };
63
+
60
64
  var filterOptionsBySearchValue = function filterOptionsBySearchValue(options, searchValue) {
61
65
  if ((options === null || options === void 0 ? void 0 : options.length) > 0) {
62
66
  if (options[0].options) return options.map(function (optionGroup) {
@@ -132,6 +136,10 @@ var getSelectedOption = function getSelectedOption(value, options, multiple, opt
132
136
  };
133
137
  };
134
138
 
139
+ var notOptionalCheck = function notOptionalCheck(value, multiple, optional) {
140
+ return !optional && (multiple ? value.length === 0 : value === "");
141
+ };
142
+
135
143
  var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
136
144
  var _selectedOption$label;
137
145
 
@@ -189,10 +197,15 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
189
197
  isOpen = _useState10[0],
190
198
  changeIsOpen = _useState10[1];
191
199
 
192
- var selectContainerRef = (0, _react.useRef)(null);
200
+ var _useState11 = (0, _react.useState)(null),
201
+ _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
202
+ listboxStyles = _useState12[0],
203
+ setListboxStyles = _useState12[1];
204
+
205
+ var selectRef = (0, _react.useRef)(null);
193
206
  var selectSearchInputRef = (0, _react.useRef)(null);
194
- var selectOptionsListRef = (0, _react.useRef)(null);
195
207
  var colorsTheme = (0, _useTheme["default"])();
208
+ var translatedLabels = (0, _useTranslatedLabels["default"])();
196
209
  var optionalItem = {
197
210
  label: placeholder,
198
211
  value: ""
@@ -210,20 +223,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
210
223
  selectedOption = _useMemo.selectedOption,
211
224
  singleSelectionIndex = _useMemo.singleSelectionIndex;
212
225
 
213
- var notOptionalCheck = function notOptionalCheck(value) {
214
- return !optional && value === "";
215
- };
216
-
217
- var notOptionalMultipleCheck = function notOptionalMultipleCheck(value) {
218
- return !optional && value.length === 0;
219
- };
220
-
221
- var canBeOpenOptions = function canBeOpenOptions() {
222
- return !disabled && (options === null || options === void 0 ? void 0 : options.length) > 0 && groupsHaveOptions(options);
223
- };
224
-
225
226
  var openOptions = function openOptions() {
226
- if (!isOpen && canBeOpenOptions()) changeIsOpen(true);
227
+ if (!isOpen && canOpenOptions(options, disabled)) changeIsOpen(true);
227
228
  };
228
229
 
229
230
  var closeOptions = function closeOptions() {
@@ -234,27 +235,21 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
234
235
  };
235
236
 
236
237
  var handleSelectChangeValue = function handleSelectChangeValue(newOption) {
238
+ var newValue;
239
+
237
240
  if (multiple) {
238
- var res = [];
239
- if ((value !== null && value !== void 0 ? value : innerValue).includes(newOption.value)) res = (value !== null && value !== void 0 ? value : innerValue).filter(function (optionVal) {
241
+ if ((value !== null && value !== void 0 ? value : innerValue).includes(newOption.value)) newValue = (value !== null && value !== void 0 ? value : innerValue).filter(function (optionVal) {
240
242
  return optionVal !== newOption.value;
241
- });else res = [].concat((0, _toConsumableArray2["default"])(value !== null && value !== void 0 ? value : innerValue), [newOption.value]);
242
- value !== null && value !== void 0 ? value : setInnerValue(res);
243
- if (notOptionalMultipleCheck(res)) onChange === null || onChange === void 0 ? void 0 : onChange({
244
- value: res,
245
- error: getNotOptionalErrorMessage()
246
- });else onChange === null || onChange === void 0 ? void 0 : onChange({
247
- value: res
248
- });
249
- } else {
250
- value !== null && value !== void 0 ? value : setInnerValue(newOption.value);
251
- if (notOptionalCheck(newOption.value)) onChange === null || onChange === void 0 ? void 0 : onChange({
252
- value: newOption.value,
253
- error: getNotOptionalErrorMessage()
254
- });else onChange === null || onChange === void 0 ? void 0 : onChange({
255
- value: newOption.value
256
- });
257
- }
243
+ });else newValue = [].concat((0, _toConsumableArray2["default"])(value !== null && value !== void 0 ? value : innerValue), [newOption.value]);
244
+ } else newValue = newOption.value;
245
+
246
+ value !== null && value !== void 0 ? value : setInnerValue(newValue);
247
+ notOptionalCheck(newValue, multiple, optional) ? onChange === null || onChange === void 0 ? void 0 : onChange({
248
+ value: newValue,
249
+ error: translatedLabels.formFields.requiredValueErrorMessage
250
+ }) : onChange === null || onChange === void 0 ? void 0 : onChange({
251
+ value: newValue
252
+ });
258
253
  };
259
254
 
260
255
  var handleSelectOnClick = function handleSelectOnClick() {
@@ -275,11 +270,12 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
275
270
  if (!event.currentTarget.contains(event.relatedTarget)) {
276
271
  closeOptions();
277
272
  setSearchValue("");
278
- if (notOptionalCheck(value !== null && value !== void 0 ? value : innerValue)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
279
- value: value !== null && value !== void 0 ? value : innerValue,
280
- error: getNotOptionalErrorMessage()
281
- });else onBlur === null || onBlur === void 0 ? void 0 : onBlur({
282
- value: value !== null && value !== void 0 ? value : innerValue
273
+ var currentValue = value !== null && value !== void 0 ? value : innerValue;
274
+ notOptionalCheck(currentValue, multiple, optional) ? onBlur === null || onBlur === void 0 ? void 0 : onBlur({
275
+ value: currentValue,
276
+ error: translatedLabels.formFields.requiredValueErrorMessage
277
+ }) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
278
+ value: currentValue
283
279
  });
284
280
  }
285
281
  };
@@ -353,7 +349,7 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
353
349
  value !== null && value !== void 0 ? value : setInnerValue([]);
354
350
  !optional ? onChange === null || onChange === void 0 ? void 0 : onChange({
355
351
  value: [],
356
- error: getNotOptionalErrorMessage()
352
+ error: translatedLabels.formFields.requiredValueErrorMessage
357
353
  }) : onChange === null || onChange === void 0 ? void 0 : onChange({
358
354
  value: []
359
355
  });
@@ -369,26 +365,23 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
369
365
  !multiple && closeOptions();
370
366
  setSearchValue("");
371
367
  }, [handleSelectChangeValue, closeOptions, multiple]);
372
- (0, _react.useLayoutEffect)(function () {
373
- if (isOpen && singleSelectionIndex) {
374
- var _listEl$scrollTo;
375
-
376
- var listEl = selectOptionsListRef === null || selectOptionsListRef === void 0 ? void 0 : selectOptionsListRef.current;
377
- var selectedListOptionEl = listEl === null || listEl === void 0 ? void 0 : listEl.querySelector("[aria-selected='true']");
378
- listEl === null || listEl === void 0 ? void 0 : (_listEl$scrollTo = listEl.scrollTo) === null || _listEl$scrollTo === void 0 ? void 0 : _listEl$scrollTo.call(listEl, {
379
- top: (selectedListOptionEl === null || selectedListOptionEl === void 0 ? void 0 : selectedListOptionEl.offsetTop) - (listEl === null || listEl === void 0 ? void 0 : listEl.clientHeight) / 2
380
- });
381
- }
382
- }, [isOpen]);
383
- (0, _react.useLayoutEffect)(function () {
384
- var _selectOptionsListRef, _visualFocusedOptionE;
385
-
386
- var visualFocusedOptionEl = selectOptionsListRef === null || selectOptionsListRef === void 0 ? void 0 : (_selectOptionsListRef = selectOptionsListRef.current) === null || _selectOptionsListRef === void 0 ? void 0 : _selectOptionsListRef.querySelectorAll("[role='option']")[visualFocusIndex];
387
- visualFocusedOptionEl === null || visualFocusedOptionEl === void 0 ? void 0 : (_visualFocusedOptionE = visualFocusedOptionEl.scrollIntoView) === null || _visualFocusedOptionE === void 0 ? void 0 : _visualFocusedOptionE.call(visualFocusedOptionEl, {
388
- block: "nearest",
389
- inline: "start"
368
+
369
+ var handleListboxResize = function handleListboxResize() {
370
+ var _selectRef$current;
371
+
372
+ var rect = selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.getBoundingClientRect();
373
+ setListboxStyles({
374
+ width: rect === null || rect === void 0 ? void 0 : rect.width
390
375
  });
391
- }, [visualFocusIndex]);
376
+ };
377
+
378
+ (0, _react.useEffect)(function () {
379
+ handleListboxResize();
380
+ window.addEventListener("resize", handleListboxResize);
381
+ return function () {
382
+ window.removeEventListener("resize", handleListboxResize);
383
+ };
384
+ }, [setListboxStyles]);
392
385
  return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
393
386
  theme: colorsTheme.select
394
387
  }, /*#__PURE__*/_react["default"].createElement(SelectContainer, {
@@ -399,12 +392,16 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
399
392
  id: selectLabelId,
400
393
  disabled: disabled,
401
394
  onClick: function onClick() {
402
- selectContainerRef.current.focus();
395
+ selectRef.current.focus();
403
396
  },
404
397
  helperText: helperText
405
- }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, "(Optional)")), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
398
+ }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
406
399
  disabled: disabled
407
- }, helperText), /*#__PURE__*/_react["default"].createElement(Select, {
400
+ }, helperText), /*#__PURE__*/_react["default"].createElement(Popover.Root, {
401
+ open: isOpen
402
+ }, /*#__PURE__*/_react["default"].createElement(Popover.Trigger, {
403
+ asChild: true
404
+ }, /*#__PURE__*/_react["default"].createElement(Select, {
408
405
  id: selectId,
409
406
  disabled: disabled,
410
407
  error: error,
@@ -412,14 +409,14 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
412
409
  onClick: handleSelectOnClick,
413
410
  onFocus: handleSelectOnFocus,
414
411
  onKeyDown: handleSelectOnKeyDown,
415
- ref: selectContainerRef,
412
+ ref: selectRef,
416
413
  tabIndex: tabIndex,
417
414
  role: "combobox",
418
415
  "aria-controls": optionsListId,
419
416
  "aria-disabled": disabled,
420
417
  "aria-expanded": isOpen,
421
418
  "aria-haspopup": "listbox",
422
- "aria-labelledby": selectLabelId,
419
+ "aria-labelledby": label ? selectLabelId : undefined,
423
420
  "aria-activedescendant": visualFocusIndex >= 0 ? "option-".concat(visualFocusIndex) : undefined,
424
421
  "aria-invalid": error ? "true" : "false",
425
422
  "aria-errormessage": error ? errorId : undefined,
@@ -434,8 +431,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
434
431
  },
435
432
  onClick: handleClearOptionsActionOnClick,
436
433
  tabIndex: -1,
437
- title: "Clear selection",
438
- "aria-label": "Clear selection"
434
+ title: translatedLabels.select.actionClearSelectionTitle,
435
+ "aria-label": translatedLabels.select.actionClearSelectionTitle
439
436
  }, _Icons["default"].clear)), /*#__PURE__*/_react["default"].createElement(SearchableValueContainer, null, /*#__PURE__*/_react["default"].createElement(ValueInput, {
440
437
  name: name,
441
438
  value: multiple ? (value !== null && value !== void 0 ? value : innerValue).join(",") : value !== null && value !== void 0 ? value : innerValue,
@@ -464,11 +461,21 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
464
461
  },
465
462
  onClick: handleClearSearchActionOnClick,
466
463
  tabIndex: -1,
467
- title: "Clear search",
468
- "aria-label": "Clear search"
464
+ title: translatedLabels.select.actionClearSearchTitle,
465
+ "aria-label": translatedLabels.select.actionClearSearchTitle
469
466
  }, _Icons["default"].clear), /*#__PURE__*/_react["default"].createElement(CollapseIndicator, {
470
467
  disabled: disabled
471
- }, isOpen ? _Icons["default"].arrowUp : _Icons["default"].arrowDown), isOpen && /*#__PURE__*/_react["default"].createElement(_Listbox["default"], {
468
+ }, isOpen ? _Icons["default"].arrowUp : _Icons["default"].arrowDown))), /*#__PURE__*/_react["default"].createElement(Popover.Content, {
469
+ sideOffset: 4,
470
+ onOpenAutoFocus: function onOpenAutoFocus(event) {
471
+ // Avoid select to lose focus when the list is opened
472
+ event.preventDefault();
473
+ },
474
+ onCloseAutoFocus: function onCloseAutoFocus(event) {
475
+ // Avoid select to lose focus when the list is closed
476
+ event.preventDefault();
477
+ }
478
+ }, /*#__PURE__*/_react["default"].createElement(_Listbox["default"], {
472
479
  id: optionsListId,
473
480
  currentValue: value !== null && value !== void 0 ? value : innerValue,
474
481
  options: searchable ? filteredOptions : options,
@@ -479,8 +486,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
479
486
  optionalItem: optionalItem,
480
487
  searchable: searchable,
481
488
  handleOptionOnClick: handleOptionOnClick,
482
- ref: selectOptionsListRef
483
- })), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
489
+ styles: listboxStyles
490
+ }))), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
484
491
  id: errorId,
485
492
  "aria-live": error ? "assertive" : "off"
486
493
  }, error)));
@@ -579,9 +586,7 @@ var SelectionNumber = _styledComponents["default"].span(_templateObject7 || (_te
579
586
  return props.disabled ? "cursor: not-allowed;" : "cursor: default;";
580
587
  });
581
588
 
582
- var ClearOptionsAction = _styledComponents["default"].button(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n width: 23px;\n height: 22px;\n font-size: 1rem;\n font-family: ", ";\n border: none;\n padding: 0.25rem;\n ", "\n background-color: ", ";\n color: ", ";\n\n :focus-visible {\n outline: none;\n }\n ", "\n\n svg {\n line-height: 18px;\n }\n"])), function (props) {
583
- return props.theme.fontFamily;
584
- }, function (props) {
589
+ var ClearOptionsAction = _styledComponents["default"].button(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n width: 23px;\n height: 22px;\n border: none;\n padding: 0.25rem;\n ", "\n background-color: ", ";\n color: ", ";\n\n :focus-visible {\n outline: none;\n }\n ", "\n\n svg {\n line-height: 18px;\n }\n"])), function (props) {
585
590
  return props.disabled ? "cursor: not-allowed;" : "cursor: pointer;";
586
591
  }, function (props) {
587
592
  return props.disabled ? "transparent" : props.theme.enabledSelectionIndicatorActionBackgroundColor;
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
-
3
2
  import { userEvent, within, waitFor } from "@storybook/testing-library";
4
- import { fireEvent } from "@testing-library/react";
5
-
6
3
  import Title from "../../.storybook/components/Title";
7
4
  import ExampleContainer from "../../.storybook/components/ExampleContainer";
8
-
9
5
  import DxcSelect from "./Select";
6
+ import Listbox from "./Listbox";
7
+ import DxcButton from "../button/Button";
8
+ import DxcCheckbox from "../checkbox/Checkbox";
10
9
 
11
10
  export default {
12
11
  title: "Select",
@@ -340,7 +339,7 @@ const Select = () => (
340
339
  <DxcSelect label="Label" options={single_options} multiple defaultValue={["1", "2", "3", "4"]} />
341
340
  <Title title="Value with ellipsis" theme="light" level={4} />
342
341
  <DxcSelect label="Label" options={optionsWithEllipsisMedium} defaultValue="1" size="medium" />
343
- <Title title="Option with ellipsis" theme="light" level={4} />
342
+ <Title title="Options with ellipsis" theme="light" level={4} />
344
343
  <DxcSelect
345
344
  label="Label"
346
345
  placeholder="Choose an option"
@@ -351,16 +350,103 @@ const Select = () => (
351
350
  </ExampleContainer>
352
351
  </>
353
352
  );
354
- export const Chromatic = Select.bind({});
355
- Chromatic.play = async ({ canvasElement }) => {
356
- const canvas = within(canvasElement);
357
- await userEvent.click(canvas.getAllByRole("combobox")[24]);
358
- };
359
- const DefaultSelect = () => (
360
- <ExampleContainer expanded>
361
- <Title title="Default select" theme="light" level={4} />
362
- <DxcSelect label="Select label" options={single_options} optional placeholder="Choose an option" />
363
- </ExampleContainer>
353
+ const SelectListbox = () => (
354
+ <>
355
+ <Title title="Listbox" theme="light" level={2} />
356
+ <Title title="Default with opened listbox" theme="light" level={3} />
357
+ <ExampleContainer>
358
+ <div style={{ display: "flex", gap: "30px", flexDirection: "column", marginBottom: "80px" }}>
359
+ <DxcSelect label="Label" options={single_options} optional placeholder="Choose an option" />
360
+ <DxcCheckbox
361
+ label="You understand the selection and give your consent"
362
+ onChange={() => {}}
363
+ labelPosition="after"
364
+ />
365
+ <DxcButton label="Submit" onClick={() => {}} size="medium" />
366
+ </div>
367
+ </ExampleContainer>
368
+ <Title title="Listbox option states" theme="light" level={3} />
369
+ <ExampleContainer pseudoState="pseudo-hover">
370
+ <Title title="Hovered option" theme="light" level={4} />
371
+ <Listbox
372
+ id="x"
373
+ currentValue=""
374
+ options={one_option}
375
+ visualFocusIndex={-1}
376
+ lastOptionIndex={0}
377
+ multiple={false}
378
+ optional={false}
379
+ optionalItem={{ label: "Empty", value: "" }}
380
+ searchable={false}
381
+ handleOptionOnClick={() => {}}
382
+ styles={{ width: 360 }}
383
+ />
384
+ </ExampleContainer>
385
+ <ExampleContainer pseudoState="pseudo-active">
386
+ <Title title="Active option" theme="light" level={4} />
387
+ <Listbox
388
+ id="x"
389
+ currentValue=""
390
+ options={one_option}
391
+ visualFocusIndex={-1}
392
+ lastOptionIndex={0}
393
+ multiple={false}
394
+ optional={false}
395
+ optionalItem={{ label: "Empty", value: "" }}
396
+ searchable={false}
397
+ handleOptionOnClick={() => {}}
398
+ styles={{ width: 360 }}
399
+ />
400
+ </ExampleContainer>
401
+ <ExampleContainer>
402
+ <Title title="Focused option" theme="light" level={4} />
403
+ <Listbox
404
+ id="x"
405
+ currentValue=""
406
+ options={one_option}
407
+ visualFocusIndex={0}
408
+ lastOptionIndex={0}
409
+ multiple={false}
410
+ optional={false}
411
+ optionalItem={{ label: "Empty", value: "" }}
412
+ searchable={false}
413
+ handleOptionOnClick={() => {}}
414
+ styles={{ width: 360 }}
415
+ />
416
+ </ExampleContainer>
417
+ <ExampleContainer pseudoState="pseudo-hover">
418
+ <Title title="Hovered selected option" theme="light" level={4} />
419
+ <Listbox
420
+ id="x"
421
+ currentValue="1"
422
+ options={single_options}
423
+ visualFocusIndex={-1}
424
+ lastOptionIndex={3}
425
+ multiple={false}
426
+ optional={false}
427
+ optionalItem={{ label: "Empty", value: "" }}
428
+ searchable={false}
429
+ handleOptionOnClick={() => {}}
430
+ styles={{ width: 360 }}
431
+ />
432
+ </ExampleContainer>
433
+ <ExampleContainer pseudoState="pseudo-active">
434
+ <Title title="Active selected option" theme="light" level={4} />
435
+ <Listbox
436
+ id="x"
437
+ currentValue="2"
438
+ options={single_options}
439
+ visualFocusIndex={0}
440
+ lastOptionIndex={3}
441
+ multiple={false}
442
+ optional={false}
443
+ optionalItem={{ label: "Empty", value: "" }}
444
+ searchable={false}
445
+ handleOptionOnClick={() => {}}
446
+ styles={{ width: 360 }}
447
+ />
448
+ </ExampleContainer>
449
+ </>
364
450
  );
365
451
  const SearchableSelect = () => (
366
452
  <ExampleContainer expanded>
@@ -368,13 +454,18 @@ const SearchableSelect = () => (
368
454
  <DxcSelect label="Select Label" searchable options={single_options} placeholder="Choose an option" />
369
455
  </ExampleContainer>
370
456
  );
371
- const SearchableWithValue = () => (
457
+ const SearchValue = () => (
372
458
  <ExampleContainer expanded>
373
459
  <Title title="Searchable select with value" theme="light" level={4} />
374
- <DxcSelect label="Select Label" searchable defaultValue="1" options={single_options} placeholder="Choose an option" />
460
+ <DxcSelect
461
+ label="Select Label"
462
+ searchable
463
+ defaultValue="1"
464
+ options={single_options}
465
+ placeholder="Choose an option"
466
+ />
375
467
  </ExampleContainer>
376
468
  );
377
-
378
469
  const MultipleSelect = () => (
379
470
  <>
380
471
  <ExampleContainer expanded>
@@ -398,7 +489,13 @@ const DefaultGroupedOptionsSelect = () => (
398
489
  const MultipleGroupedOptionsSelect = () => (
399
490
  <ExampleContainer expanded>
400
491
  <Title title="Grouped options multiple select" theme="light" level={4} />
401
- <DxcSelect label="Label" options={group_options} defaultValue={["0", "2"]} multiple placeholder="Choose an option" />
492
+ <DxcSelect
493
+ label="Label"
494
+ options={group_options}
495
+ defaultValue={["0", "2"]}
496
+ multiple
497
+ placeholder="Choose an option"
498
+ />
402
499
  </ExampleContainer>
403
500
  );
404
501
  const RescaledIcons = () => (
@@ -431,36 +528,7 @@ const MultipleGroupedOptionsSelectWithIcons = () => (
431
528
  />
432
529
  </ExampleContainer>
433
530
  );
434
- const OnlyOneOptionHovered = () => (
435
- <ExampleContainer pseudoState="pseudo-hover" expanded>
436
- <Title title="Hovered Option" theme="light" level={4} />
437
- <DxcSelect label="Hovered" options={one_option} placeholder="Choose an option" />
438
- </ExampleContainer>
439
- );
440
- const OnlyOneOptionFocused = () => (
441
- <ExampleContainer pseudoState="pseudo-focus" expanded>
442
- <Title title="Focused Option" theme="light" level={4} />
443
- <DxcSelect label="Focused" options={one_option} placeholder="Choose an option" />
444
- </ExampleContainer>
445
- );
446
- const OnlyOneOptionActived = () => (
447
- <ExampleContainer pseudoState="pseudo-active" expanded>
448
- <Title title="Actived Option" theme="light" level={4} />
449
- <DxcSelect label="Actived" options={one_option} placeholder="Choose an option" />
450
- </ExampleContainer>
451
- );
452
- const SelectedOptionHovered = () => (
453
- <ExampleContainer pseudoState="pseudo-hover" expanded>
454
- <Title title="Hovered Selected Option" theme="light" level={4} />
455
- <DxcSelect label="Hovered" defaultValue="1" options={one_option} placeholder="Choose an option" />
456
- </ExampleContainer>
457
- );
458
- const SelectedOptionActived = () => (
459
- <ExampleContainer pseudoState="pseudo-active" expanded>
460
- <Title title="Actived Selected Option" theme="light" level={4} />
461
- <DxcSelect label="Actived" defaultValue="1" options={one_option} placeholder="Choose an option" />
462
- </ExampleContainer>
463
- );
531
+
464
532
  const MultipleSearchable = () => (
465
533
  <ExampleContainer expanded>
466
534
  <Title title="Searchable multiple select with value" theme="light" level={4} />
@@ -474,12 +542,20 @@ const MultipleSearchable = () => (
474
542
  />
475
543
  </ExampleContainer>
476
544
  );
477
- export const OptionsDisplayed = DefaultSelect.bind({});
478
- OptionsDisplayed.play = async ({ canvasElement }) => {
545
+
546
+ export const Chromatic = Select.bind({});
547
+ Chromatic.play = async ({ canvasElement }) => {
548
+ const canvas = within(canvasElement);
549
+ await userEvent.click(canvas.getAllByRole("combobox")[24]);
550
+ };
551
+
552
+ export const ListboxStates = SelectListbox.bind({});
553
+ ListboxStates.play = async ({ canvasElement }) => {
479
554
  const canvas = within(canvasElement);
480
555
  const select = canvas.getByRole("combobox");
481
556
  await userEvent.click(select);
482
557
  };
558
+
483
559
  export const Searchable = SearchableSelect.bind({});
484
560
  Searchable.play = async ({ canvasElement }) => {
485
561
  const canvas = within(canvasElement);
@@ -488,14 +564,15 @@ Searchable.play = async ({ canvasElement }) => {
488
564
  userEvent.type(canvas.getByRole("combobox"), "r");
489
565
  });
490
566
  };
491
- export const SelectSearchableWithValue = SearchableWithValue.bind({});
492
- SelectSearchableWithValue.play = async ({ canvasElement }) => {
567
+
568
+ export const SearchableWithValue = SearchValue.bind({});
569
+ SearchableWithValue.play = async ({ canvasElement }) => {
493
570
  const canvas = within(canvasElement);
494
571
  await userEvent.click(canvas.getByRole("combobox"));
495
572
  };
496
573
 
497
- export const SelectMultipleSearchableWithValue = MultipleSearchable.bind({});
498
- SelectMultipleSearchableWithValue.play = async ({ canvasElement }) => {
574
+ export const MultipleSearchableWithValue = MultipleSearchable.bind({});
575
+ MultipleSearchableWithValue.play = async ({ canvasElement }) => {
499
576
  const canvas = within(canvasElement);
500
577
  await userEvent.click(canvas.getAllByRole("combobox")[0]);
501
578
  };
@@ -507,75 +584,42 @@ GroupOptionsDisplayed.play = async ({ canvasElement }) => {
507
584
  await userEvent.click(select);
508
585
  };
509
586
 
510
- export const SelectMultipleOptionsDisplayed = MultipleSelect.bind({});
511
- SelectMultipleOptionsDisplayed.play = async ({ canvasElement }) => {
587
+ export const MultipleOptionsDisplayed = MultipleSelect.bind({});
588
+ MultipleOptionsDisplayed.play = async ({ canvasElement }) => {
512
589
  const canvas = within(canvasElement);
513
590
  await userEvent.click(canvas.getAllByRole("combobox")[0]);
514
591
  };
515
592
 
516
- export const SelectMultipleGroupedOptionsDisplayed = MultipleGroupedOptionsSelect.bind({});
517
- SelectMultipleGroupedOptionsDisplayed.play = async ({ canvasElement }) => {
518
- const canvas = within(canvasElement);
519
- const select = canvas.getByRole("combobox");
520
- await userEvent.click(select);
521
- };
522
- export const SelectWithIconsDisplayed = SelectWithIcons.bind({});
523
- SelectWithIconsDisplayed.play = async ({ canvasElement }) => {
593
+ export const MultipleGroupedOptionsDisplayed = MultipleGroupedOptionsSelect.bind({});
594
+ MultipleGroupedOptionsDisplayed.play = async ({ canvasElement }) => {
524
595
  const canvas = within(canvasElement);
525
596
  const select = canvas.getByRole("combobox");
526
597
  await userEvent.click(select);
527
598
  };
528
599
 
529
- export const SelectWithRescaledIconsDisplayed = RescaledIcons.bind({});
530
- SelectWithRescaledIconsDisplayed.play = async ({ canvasElement }) => {
531
- const canvas = within(canvasElement);
532
- const select = canvas.getByRole("combobox");
533
- await userEvent.click(select);
534
- };
535
- export const SelectMultipleWithIconsDisplayed = SelectMultipleWithIcons.bind({});
536
- SelectMultipleWithIconsDisplayed.play = async ({ canvasElement }) => {
600
+ export const WithIconsDisplayed = SelectWithIcons.bind({});
601
+ WithIconsDisplayed.play = async ({ canvasElement }) => {
537
602
  const canvas = within(canvasElement);
538
603
  const select = canvas.getByRole("combobox");
539
604
  await userEvent.click(select);
540
605
  };
541
606
 
542
- export const SelectMultipleGroupedWithIconsDisplayed = MultipleGroupedOptionsSelectWithIcons.bind({});
543
- SelectMultipleGroupedWithIconsDisplayed.play = async ({ canvasElement }) => {
607
+ export const WithRescaledIconsDisplayed = RescaledIcons.bind({});
608
+ WithRescaledIconsDisplayed.play = async ({ canvasElement }) => {
544
609
  const canvas = within(canvasElement);
545
610
  const select = canvas.getByRole("combobox");
546
611
  await userEvent.click(select);
547
612
  };
548
613
 
549
- export const OptionHovered = OnlyOneOptionHovered.bind({});
550
- OptionHovered.play = async ({ canvasElement }) => {
614
+ export const MultipleWithIconsDisplayed = SelectMultipleWithIcons.bind({});
615
+ MultipleWithIconsDisplayed.play = async ({ canvasElement }) => {
551
616
  const canvas = within(canvasElement);
552
617
  const select = canvas.getByRole("combobox");
553
618
  await userEvent.click(select);
554
619
  };
555
620
 
556
- export const OptionFocused = OnlyOneOptionFocused.bind({});
557
- OptionFocused.play = async ({ canvasElement }) => {
558
- const canvas = within(canvasElement);
559
- const select = canvas.getByRole("combobox");
560
- await userEvent.click(select);
561
- await waitFor(async () => {
562
- fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
563
- });
564
- };
565
- export const OptionActived = OnlyOneOptionActived.bind({});
566
- OptionActived.play = async ({ canvasElement }) => {
567
- const canvas = within(canvasElement);
568
- const select = canvas.getByRole("combobox");
569
- await userEvent.click(select);
570
- };
571
- export const OptionSelectedHovered = SelectedOptionHovered.bind({});
572
- OptionSelectedHovered.play = async ({ canvasElement }) => {
573
- const canvas = within(canvasElement);
574
- const select = canvas.getByRole("combobox");
575
- await userEvent.click(select);
576
- };
577
- export const OptionSelectedActived = SelectedOptionActived.bind({});
578
- OptionSelectedActived.play = async ({ canvasElement }) => {
621
+ export const MultipleGroupedWithIconsDisplayed = MultipleGroupedOptionsSelectWithIcons.bind({});
622
+ MultipleGroupedWithIconsDisplayed.play = async ({ canvasElement }) => {
579
623
  const canvas = within(canvasElement);
580
624
  const select = canvas.getByRole("combobox");
581
625
  await userEvent.click(select);