@ultraviolet/ui 1.48.1 → 1.50.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.
@@ -91,7 +91,7 @@ const DropdownItem = /*#__PURE__*/_styled("button", {
91
91
  theme
92
92
  }) => theme.colors.primary.background, ";color:", ({
93
93
  theme
94
- }) => theme.colors.primary.text, ";cursor:'pointer';outline:none;}&[data-selected='true']{background-color:", ({
94
+ }) => theme.colors.primary.text, ";cursor:pointer;outline:none;}&[data-selected='true']{background-color:", ({
95
95
  theme
96
96
  }) => theme.colors.primary.background, ";}&[disabled]{background-color:", ({
97
97
  theme
@@ -118,13 +118,14 @@ const PopupFooter = /*#__PURE__*/_styled("div", {
118
118
  const StyledCheckbox = /*#__PURE__*/_styled(Checkbox, {
119
119
  target: "eeucz6c2"
120
120
  })(process.env.NODE_ENV === "production" ? {
121
- name: "10y07ze",
122
- styles: "width:100%;position:static;text-align:left;align-items:center"
121
+ name: "1l9xw77",
122
+ styles: "width:100%;position:static;text-align:left;align-items:center;pointer-events:none"
123
123
  } : {
124
- name: "10y07ze",
125
- styles: "width:100%;position:static;text-align:left;align-items:center",
124
+ name: "1l9xw77",
125
+ styles: "width:100%;position:static;text-align:left;align-items:center;pointer-events:none",
126
126
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
127
- });
127
+ }); // pointer-events: none prevents any error when using the checkbox in a form since it is an unnamed input
128
+
128
129
  const EmptyState = /*#__PURE__*/_styled(Stack, {
129
130
  target: "eeucz6c1"
130
131
  })("padding:", ({
@@ -206,7 +207,6 @@ const CreateDropdown = ({
206
207
  isEmpty,
207
208
  emptyState,
208
209
  descriptionDirection,
209
- onChange,
210
210
  loadMore,
211
211
  optionalInfoPlacement,
212
212
  defaultSearchValue,
@@ -214,6 +214,7 @@ const CreateDropdown = ({
214
214
  }) => {
215
215
  const {
216
216
  setIsDropdownVisible,
217
+ onChange,
217
218
  options,
218
219
  multiselect,
219
220
  selectAll,
@@ -246,50 +247,54 @@ const CreateDropdown = ({
246
247
  group
247
248
  });
248
249
  if (multiselect) {
249
- if (selectedData.selectedValues.includes(clickedOption)) {
250
- onChange?.(selectedData.selectedValues.filter(val => val !== clickedOption).map(val => val?.value));
250
+ if (selectedData.selectedValues.includes(clickedOption.value)) {
251
+ onChange?.(selectedData.selectedValues.filter(val => val !== clickedOption.value));
251
252
  } else {
252
- onChange?.([...selectedData.selectedValues, clickedOption].map(val => val?.value));
253
+ onChange?.([...selectedData.selectedValues, clickedOption.value]);
253
254
  }
254
255
  } else {
255
- onChange?.([clickedOption.value]);
256
+ onChange?.(clickedOption.value);
256
257
  }
257
258
  setIsDropdownVisible(multiselect); // hide the dropdown on click when single select only
258
259
  };
259
260
  const selectAllOptions = () => {
260
- setSelectedData({
261
- type: 'selectAll'
262
- });
263
- if (selectedData.allSelected && onChange) {
264
- onChange?.([]);
265
- } else {
266
- const allValues = [];
267
- if (!Array.isArray(options)) {
268
- Object.keys(options).map(group => options[group].map(option => {
269
- if (!option.disabled) {
270
- allValues.push(option);
271
- }
272
- return null;
273
- }));
261
+ if (multiselect) {
262
+ setSelectedData({
263
+ type: 'selectAll'
264
+ });
265
+ if (selectedData.allSelected && onChange) {
266
+ onChange([]);
274
267
  } else {
275
- options.map(option => allValues.push(option));
268
+ const allValues = [];
269
+ if (!Array.isArray(options)) {
270
+ Object.keys(options).map(group => options[group].map(option => {
271
+ if (!option.disabled) {
272
+ allValues.push(option);
273
+ }
274
+ return null;
275
+ }));
276
+ } else {
277
+ options.map(option => allValues.push(option));
278
+ }
279
+ onChange?.(allValues.map(value => value.value));
276
280
  }
277
- onChange?.(allValues.map(value => value.value));
278
281
  }
279
282
  };
280
283
  const handleSelectGroup = group => {
281
- setSelectedData({
282
- type: 'selectGroup',
283
- selectedGroup: group
284
- });
285
- if (!Array.isArray(options)) {
286
- if (selectedData.selectedGroups.includes(group)) {
287
- const newSelectedValues = [...selectedData.selectedValues].filter(selectedValue => !options[group].includes(selectedValue));
288
- onChange?.(newSelectedValues.map(value => value.value));
289
- } else {
290
- const newSelectedValues = [...selectedData.selectedValues];
291
- options[group].map(option => newSelectedValues.includes(option) || option.disabled ? null : newSelectedValues.push(option));
292
- onChange?.(newSelectedValues.map(value => value.value));
284
+ if (multiselect) {
285
+ setSelectedData({
286
+ type: 'selectGroup',
287
+ selectedGroup: group
288
+ });
289
+ if (!Array.isArray(options)) {
290
+ if (selectedData.selectedGroups.includes(group)) {
291
+ const newSelectedValues = [...selectedData.selectedValues].filter(selectedValue => !options[group].find(option => option.value === selectedValue));
292
+ onChange?.(newSelectedValues);
293
+ } else {
294
+ const newSelectedValues = [...selectedData.selectedValues];
295
+ options[group].map(option => newSelectedValues.includes(option.value) || option.disabled ? null : newSelectedValues.push(option.value));
296
+ onChange?.(newSelectedValues);
297
+ }
293
298
  }
294
299
  }
295
300
  };
@@ -314,12 +319,12 @@ const CreateDropdown = ({
314
319
  id: "select-all",
315
320
  role: "option",
316
321
  onKeyDown: event => [' ', 'Enter'].includes(event.key) ? selectAllOptions() : null,
322
+ onClick: selectAllOptions,
317
323
  children: jsx(StyledCheckbox, {
318
324
  checked: selectedData.allSelected,
319
325
  disabled: false,
320
326
  value: "select-all",
321
327
  "data-testid": "select-all-checkbox",
322
- onChange: selectAllOptions,
323
328
  tabIndex: -1,
324
329
  children: jsxs(Stack, {
325
330
  direction: "column",
@@ -339,7 +344,7 @@ const CreateDropdown = ({
339
344
  })
340
345
  })
341
346
  })
342
- }) : null, Object.keys(displayedOptions).map(group => jsxs(Stack, {
347
+ }) : null, Object.keys(displayedOptions).map((group, index) => jsxs(Stack, {
343
348
  gap: 0.25,
344
349
  children: [displayedOptions[group].length > 0 ? jsx(DropdownGroupWrapper, {
345
350
  id: selectAllGroup ? 'items' : undefined,
@@ -353,11 +358,12 @@ const CreateDropdown = ({
353
358
  },
354
359
  "data-selectgroup": selectAllGroup,
355
360
  role: "group",
361
+ "data-testid": `group-${index}`,
362
+ onClick: () => selectAllGroup ? handleSelectGroup(group) : null,
356
363
  children: selectAllGroup ? jsx(StyledCheckbox, {
357
364
  checked: selectedData.selectedGroups.includes(group),
358
365
  disabled: false,
359
366
  value: group,
360
- onChange: () => handleSelectGroup(group),
361
367
  "data-testid": "select-group",
362
368
  tabIndex: -1,
363
369
  children: jsx(Text, {
@@ -376,12 +382,12 @@ const CreateDropdown = ({
376
382
  }) : null, jsxs(Stack, {
377
383
  id: "items",
378
384
  gap: "0.25",
379
- children: [displayedOptions[group].map((option, index) => jsx(DropdownItem, {
385
+ children: [displayedOptions[group].map((option, indexOption) => jsx(DropdownItem, {
380
386
  disabled: option.disabled,
381
- "data-selected": selectedData.selectedValues.includes(option) && !option.disabled,
387
+ "data-selected": selectedData.selectedValues.includes(option.value) && !option.disabled,
382
388
  "aria-label": option.value,
383
- "data-testid": `option-${index}`,
384
- id: `option-${index}`,
389
+ "data-testid": `option-${option.value}`,
390
+ id: `option-${indexOption}`,
385
391
  role: "option",
386
392
  onClick: () => {
387
393
  if (!option.disabled) {
@@ -391,19 +397,17 @@ const CreateDropdown = ({
391
397
  onKeyDown: event => [' ', 'Enter'].includes(event.key) ? handleClick(option, group) : null,
392
398
  ref: option.value === defaultSearchValue || option.searchText === defaultSearchValue ? focusedItemRef : null,
393
399
  children: multiselect ? jsx(StyledCheckbox, {
394
- checked: selectedData.selectedValues.includes(option) && !option.disabled,
400
+ checked: selectedData.selectedValues.includes(option.value) && !option.disabled,
395
401
  disabled: option.disabled,
396
402
  value: option.value,
397
403
  tabIndex: -1,
398
404
  children: jsx(DisplayOption, {
399
405
  option: option,
400
- multiselect: multiselect,
401
406
  descriptionDirection: descriptionDirection,
402
407
  optionalInfoPlacement: optionalInfoPlacement
403
408
  })
404
409
  }) : jsx(DisplayOption, {
405
410
  option: option,
406
- multiselect: multiselect,
407
411
  descriptionDirection: descriptionDirection,
408
412
  optionalInfoPlacement: optionalInfoPlacement
409
413
  })
@@ -432,12 +436,12 @@ const CreateDropdown = ({
432
436
  "data-testid": "select-all",
433
437
  role: "option",
434
438
  onKeyDown: event => [' ', 'Enter'].includes(event.key) ? selectAllOptions() : null,
439
+ onClick: selectAllOptions,
435
440
  children: jsx(StyledCheckbox, {
436
441
  checked: selectedData.allSelected,
437
442
  disabled: false,
438
443
  value: "select-all",
439
444
  "data-testid": "select-all-checkbox",
440
- onChange: selectAllOptions,
441
445
  tabIndex: -1,
442
446
  children: jsxs(Stack, {
443
447
  direction: "column",
@@ -464,32 +468,30 @@ const CreateDropdown = ({
464
468
  variant: "block"
465
469
  }) : displayedOptions.map((option, index) => jsx(DropdownItem, {
466
470
  disabled: option.disabled,
467
- "data-selected": selectedData.selectedValues.includes(option) && !option.disabled,
471
+ "data-selected": selectedData.selectedValues.includes(option.value) && !option.disabled,
468
472
  onClick: () => {
469
473
  if (!option.disabled) {
470
474
  handleClick(option);
471
475
  }
472
476
  },
473
477
  "aria-label": option.value,
474
- "data-testid": `option-${index}`,
478
+ "data-testid": `option-${option.value}`,
475
479
  id: `option-${index}`,
476
480
  role: "option",
477
481
  ref: option.value === defaultSearchValue || option.searchText === defaultSearchValue ? focusedItemRef : null,
478
482
  onKeyDown: event => [' ', 'Enter'].includes(event.key) ? handleClick(option) : null,
479
483
  children: multiselect ? jsx(StyledCheckbox, {
480
- checked: selectedData.selectedValues.includes(option) && !option.disabled,
484
+ checked: selectedData.selectedValues.includes(option.value) && !option.disabled,
481
485
  disabled: option.disabled,
482
486
  value: option.value,
483
487
  tabIndex: -1,
484
488
  children: jsx(DisplayOption, {
485
489
  option: option,
486
- multiselect: multiselect,
487
490
  descriptionDirection: descriptionDirection,
488
491
  optionalInfoPlacement: optionalInfoPlacement
489
492
  })
490
493
  }) : jsx(DisplayOption, {
491
494
  option: option,
492
- multiselect: multiselect,
493
495
  descriptionDirection: descriptionDirection,
494
496
  optionalInfoPlacement: optionalInfoPlacement
495
497
  })
@@ -506,7 +508,6 @@ const Dropdown = ({
506
508
  searchable,
507
509
  placeholder,
508
510
  footer,
509
- onChange,
510
511
  refSelect,
511
512
  loadMore,
512
513
  optionalInfoPlacement,
@@ -564,13 +565,11 @@ const Dropdown = ({
564
565
  children: [searchable && !isLoading ? jsx(SearchBarDropdown, {
565
566
  placeholder: placeholder,
566
567
  displayedOptions: displayedOptions,
567
- setSearchBarActive: setSearchBarActive,
568
- onChange: onChange
568
+ setSearchBarActive: setSearchBarActive
569
569
  }) : null, jsx(CreateDropdown, {
570
570
  isEmpty: isEmpty,
571
571
  emptyState: emptyState,
572
572
  descriptionDirection: descriptionDirection,
573
- onChange: onChange,
574
573
  loadMore: loadMore,
575
574
  optionalInfoPlacement: optionalInfoPlacement,
576
575
  defaultSearchValue: defaultSearchValue,
@@ -16,7 +16,6 @@ const StyledInfo = /*#__PURE__*/_styled("div", {
16
16
  });
17
17
  const DisplayOption = ({
18
18
  option,
19
- multiselect,
20
19
  optionalInfoPlacement,
21
20
  descriptionDirection
22
21
  }) => {
@@ -25,7 +24,6 @@ const DisplayOption = ({
25
24
  gap: 0.5,
26
25
  direction: "row",
27
26
  justifyContent: "left",
28
- onClick: event => multiselect ? event.stopPropagation() : null,
29
27
  "data-testid": `option-stack-${option.value}`,
30
28
  children: jsxs(Stack, {
31
29
  gap: 0.5,
@@ -52,7 +50,6 @@ const DisplayOption = ({
52
50
  gap: 0.5,
53
51
  direction: "row",
54
52
  justifyContent: "space-between",
55
- onClick: event => multiselect ? event.stopPropagation() : null,
56
53
  alignItems: "baseline",
57
54
  "data-testid": `option-stack-${option.value}`,
58
55
  children: [jsxs(Stack, {
@@ -85,7 +82,6 @@ const DisplayOption = ({
85
82
  children: [option.optionalInfo ?? null, jsxs(Stack, {
86
83
  gap: 0.5,
87
84
  direction: "column",
88
- onClick: event => multiselect ? event.stopPropagation() : null,
89
85
  "data-testid": `option-stack-${option.value}`,
90
86
  children: [jsx(Text, {
91
87
  as: "span",
@@ -107,7 +103,6 @@ const DisplayOption = ({
107
103
  gap: 0.5,
108
104
  direction: "column",
109
105
  alignItems: "normal",
110
- onClick: event => multiselect ? event.stopPropagation() : null,
111
106
  "data-testid": `option-stack-${option.value}`,
112
107
  children: [jsxs(Stack, {
113
108
  gap: 0.5,
@@ -41,10 +41,10 @@ const findClosestOption = (options, searchInput) => {
41
41
  const SearchBarDropdown = ({
42
42
  placeholder,
43
43
  displayedOptions,
44
- setSearchBarActive,
45
- onChange
44
+ setSearchBarActive
46
45
  }) => {
47
46
  const {
47
+ onChange,
48
48
  onSearch,
49
49
  setSearchInput,
50
50
  searchInput,
@@ -85,14 +85,14 @@ const SearchBarDropdown = ({
85
85
  clickedOption: closestOption,
86
86
  group: !Array.isArray(options) ? Object.keys(options).filter(group => options[group].includes(closestOption))[0] : undefined
87
87
  });
88
- onChange?.(selectedData.selectedValues.includes(closestOption) ? selectedData.selectedValues.map(val => val?.value) : [...selectedData.selectedValues, closestOption].map(val => val?.value));
88
+ onChange?.(selectedData.selectedValues.includes(closestOption.value) ? selectedData.selectedValues : [...selectedData.selectedValues, closestOption.value]);
89
89
  setSearchInput(closestOption.searchText ?? closestOption.value);
90
90
  } else {
91
91
  setSelectedData({
92
92
  type: 'selectOption',
93
93
  clickedOption: closestOption
94
94
  });
95
- onChange?.(selectedData.selectedValues.map(val => val?.value));
95
+ onChange?.(selectedData.selectedValues[0] ?? '');
96
96
  }
97
97
  }
98
98
  }
@@ -6,6 +6,7 @@ import { Stack } from '../Stack/index.js';
6
6
  import { Tag } from '../Tag/index.js';
7
7
  import { Text } from '../Text/index.js';
8
8
  import { useSelectInput } from './SelectInputProvider.js';
9
+ import { findOptionInOptions } from './findOptionInOptions.js';
9
10
  import { INPUT_SIZE_HEIGHT, SIZES_TAG } from './types.js';
10
11
  import { jsxs, jsx } from '@emotion/react/jsx-runtime';
11
12
 
@@ -25,9 +26,7 @@ const StyledInputWrapper = /*#__PURE__*/_styled(Stack, {
25
26
  theme
26
27
  }) => theme.colors.neutral.background, ";border-radius:", ({
27
28
  theme
28
- }) => theme.radii.default, ";&:hover,:focus{border-color:", ({
29
- theme
30
- }) => theme.colors.primary.borderHover, ";outline:none;}&[data-readonly='true']{background:", ({
29
+ }) => theme.radii.default, ";&[data-readonly='true']{background:", ({
31
30
  theme
32
31
  }) => theme.colors.neutral.backgroundWeak, ";border-color:", ({
33
32
  theme
@@ -35,7 +34,7 @@ const StyledInputWrapper = /*#__PURE__*/_styled(Stack, {
35
34
  theme
36
35
  }) => theme.colors.neutral.backgroundDisabled, ";border-color:", ({
37
36
  theme
38
- }) => theme.colors.neutral.borderDisabled, ";cursor:not-allowed;}&[data-size='small']{height:", INPUT_SIZE_HEIGHT.small, "px;}&[data-size='medium']{height:", INPUT_SIZE_HEIGHT.medium, "px;}&[data-size='larger']{height:", INPUT_SIZE_HEIGHT.large, "px;}&[data-state='neutral']{border:1px solid ", ({
37
+ }) => theme.colors.neutral.borderDisabled, ";cursor:not-allowed;}&[data-size='small']{height:", INPUT_SIZE_HEIGHT.small, "px;}&[data-size='medium']{height:", INPUT_SIZE_HEIGHT.medium, "px;}&[data-size='large']{height:", INPUT_SIZE_HEIGHT.large, "px;}&[data-state='neutral']{border:1px solid ", ({
39
38
  theme
40
39
  }) => theme.colors.neutral.border, ";}&[data-state='success']{border:1px solid ", ({
41
40
  theme
@@ -45,7 +44,9 @@ const StyledInputWrapper = /*#__PURE__*/_styled(Stack, {
45
44
  theme
46
45
  }) => theme.colors.primary.border, ";}&:not([data-disabled='true']):not([data-readonly]):active{box-shadow:", ({
47
46
  theme
48
- }) => theme.shadows.focusPrimary, ";}&[data-dropdownvisible='true']{box-shadow:", ({
47
+ }) => theme.shadows.focusPrimary, ";}&:hover,:focus{border-color:", ({
48
+ theme
49
+ }) => theme.colors.primary.borderHover, ";outline:none;}&[data-dropdownvisible='true']{box-shadow:", ({
49
50
  theme
50
51
  }) => theme.shadows.focusPrimary, ";border-color:", ({
51
52
  theme
@@ -69,53 +70,58 @@ const StyledPlaceholder = /*#__PURE__*/_styled(Text, {
69
70
  }) => theme.typography.body.fontSize, ";display:flex;flex:1;align-self:center;&[data-disabled='true']{color:", ({
70
71
  theme
71
72
  }) => theme.colors.neutral.textWeakDisabled, ";}");
72
- const isValidSelectedValue = (selectedValue, options) => !Array.isArray(options) ? Object.keys(options).some(group => options[group].some(option => option === selectedValue && !option.disabled)) : options.some(option => option === selectedValue && !option.disabled);
73
+ const isValidSelectedValue = (selectedValue, options) => !Array.isArray(options) ? Object.keys(options).some(group => options[group].some(option => option.value === selectedValue && !option.disabled)) : options.some(option => option.value === selectedValue && !option.disabled);
73
74
  const DisplayValues = ({
74
- multiselect,
75
75
  refTag,
76
76
  nonOverflowedValues,
77
77
  disabled,
78
78
  readOnly,
79
- onChange,
80
79
  overflowed,
81
80
  overflowAmount,
82
- setSelectedData,
83
- selectedData,
84
81
  size
85
- }) => multiselect ? jsxs(Stack, {
86
- direction: "row",
87
- gap: "1",
88
- wrap: "nowrap",
89
- ref: refTag,
90
- alignItems: "center",
91
- children: [nonOverflowedValues.map(option => jsx(CustomTag, {
92
- "data-testid": "selected-options-tags",
93
- sentiment: "neutral",
94
- disabled: disabled,
95
- onClose: !readOnly ? event => {
96
- event.stopPropagation();
97
- setSelectedData({
98
- type: 'selectOption',
99
- clickedOption: option
100
- });
101
- const newSelectedValues = selectedData.selectedValues?.filter(val => val !== option);
102
- onChange?.(newSelectedValues.map(val => val?.value));
103
- } : undefined,
104
- children: option?.label
105
- }, option?.value)), overflowed ? jsxs(Tag, {
106
- sentiment: "neutral",
107
- disabled: disabled,
108
- "data-testid": "plus-tag",
109
- "aria-label": "Plus tag",
110
- children: [jsx(Icon, {
111
- name: "plus"
112
- }), overflowAmount]
113
- }, "+") : null]
114
- }) : jsx(Text, {
115
- as: "p",
116
- variant: size === 'large' ? 'body' : 'bodySmall',
117
- children: selectedData.selectedValues[0]?.label
118
- });
82
+ }) => {
83
+ const {
84
+ multiselect,
85
+ selectedData,
86
+ setSelectedData,
87
+ options,
88
+ onChange
89
+ } = useSelectInput();
90
+ return multiselect ? jsxs(Stack, {
91
+ direction: "row",
92
+ gap: "1",
93
+ wrap: "nowrap",
94
+ ref: refTag,
95
+ alignItems: "center",
96
+ children: [nonOverflowedValues.map(option => jsx(CustomTag, {
97
+ "data-testid": "selected-options-tags",
98
+ sentiment: "neutral",
99
+ disabled: disabled,
100
+ onClose: !readOnly ? event => {
101
+ event.stopPropagation();
102
+ setSelectedData({
103
+ type: 'selectOption',
104
+ clickedOption: option
105
+ });
106
+ const newSelectedValues = selectedData.selectedValues?.filter(val => val !== option.value);
107
+ onChange?.(newSelectedValues);
108
+ } : undefined,
109
+ children: option?.label
110
+ }, option?.value)), overflowed ? jsxs(Tag, {
111
+ sentiment: "neutral",
112
+ disabled: disabled,
113
+ "data-testid": "plus-tag",
114
+ "aria-label": "Plus tag",
115
+ children: [jsx(Icon, {
116
+ name: "plus"
117
+ }), overflowAmount]
118
+ }, "+") : null]
119
+ }) : jsx(Text, {
120
+ as: "p",
121
+ variant: size === 'large' ? 'body' : 'bodySmall',
122
+ children: selectedData.selectedValues[0] ? findOptionInOptions(options, selectedData.selectedValues[0])?.label : null
123
+ });
124
+ };
119
125
  const SelectBar = ({
120
126
  size,
121
127
  clearable,
@@ -124,24 +130,30 @@ const SelectBar = ({
124
130
  placeholder,
125
131
  success,
126
132
  error,
127
- onChange,
128
133
  autoFocus,
129
134
  innerRef
130
135
  }) => {
131
136
  const {
132
137
  isDropdownVisible,
138
+ onChange,
133
139
  setIsDropdownVisible,
134
140
  options,
135
- multiselect,
136
141
  selectedData,
137
- setSelectedData
142
+ setSelectedData,
143
+ multiselect
138
144
  } = useSelectInput();
139
145
  const openable = !(readOnly || disabled);
140
146
  const refTag = useRef(null);
141
147
  const width = innerRef.current?.offsetWidth;
142
148
  const [overflowed, setOverflowed] = useState(false);
143
149
  const [overflowAmount, setOverflowAmount] = useState(0);
144
- const [nonOverflowedValues, setNonOverFlowedValues] = useState(selectedData.selectedValues[0] ? [selectedData.selectedValues[0]] : []);
150
+ const [nonOverflowedValues, setNonOverFlowedValues] = useState(() => {
151
+ if (selectedData.selectedValues[0]) {
152
+ const firstSelectOption = findOptionInOptions(options, selectedData.selectedValues[0]);
153
+ return firstSelectOption ? [firstSelectOption] : [];
154
+ }
155
+ return [];
156
+ });
145
157
  const state = useMemo(() => {
146
158
  if (error) {
147
159
  return 'danger';
@@ -158,14 +170,15 @@ const SelectBar = ({
158
170
  let computedNonOverflowedValues = [];
159
171
  const newSelectedValues = selectedData.selectedValues.filter(selectedValue => isValidSelectedValue(selectedValue, options));
160
172
  for (const selectedValue of newSelectedValues) {
161
- if (selectedValue && selectedValue.label && width && isValidSelectedValue(selectedValue, options)) {
162
- const lengthValue = selectedValue.value.length; // Find a better way to find the number of displayed characters?
173
+ const selectedOption = findOptionInOptions(options, selectedValue);
174
+ if (selectedOption?.label && width && isValidSelectedValue(selectedValue, options)) {
175
+ const lengthValue = selectedOption.value.length; // Find a better way to find the number of displayed characters?
163
176
  const totalTagWidth = SIZES_TAG.tagWidth + SIZES_TAG.letterWidth * lengthValue;
164
177
  if (totalTagWidth + tagsWidth > width - 100) {
165
178
  computedOverflowAmount += 1;
166
179
  setOverflowAmount(computedOverflowAmount);
167
180
  } else {
168
- computedNonOverflowedValues = [...computedNonOverflowedValues, selectedValue];
181
+ computedNonOverflowedValues = [...computedNonOverflowedValues, selectedOption];
169
182
  setNonOverFlowedValues(computedNonOverflowedValues);
170
183
  tagsWidth += totalTagWidth;
171
184
  }
@@ -214,14 +227,10 @@ const SelectBar = ({
214
227
  "aria-controls": "select-dropdown",
215
228
  tabIndex: 0,
216
229
  children: [selectedData.selectedValues.length > 0 ? jsx(DisplayValues, {
217
- multiselect: multiselect,
218
230
  refTag: refTag,
219
231
  nonOverflowedValues: nonOverflowedValues,
220
232
  disabled: disabled,
221
233
  readOnly: readOnly,
222
- selectedData: selectedData,
223
- setSelectedData: setSelectedData,
224
- onChange: onChange,
225
234
  overflowed: overflowed,
226
235
  overflowAmount: overflowAmount,
227
236
  size: size
@@ -251,7 +260,11 @@ const SelectBar = ({
251
260
  setSelectedData({
252
261
  type: 'clearAll'
253
262
  });
254
- onChange?.([]);
263
+ if (multiselect) {
264
+ onChange?.([]);
265
+ } else {
266
+ onChange?.('');
267
+ }
255
268
  },
256
269
  sentiment: "neutral",
257
270
  "data-testid": "clear-all"