dash-core-components 4.0.0-rc1 → 4.0.0-rc3

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 (103) hide show
  1. package/dash_core_components/async-datepicker.js +1 -1
  2. package/dash_core_components/async-datepicker.js.map +1 -1
  3. package/dash_core_components/async-dropdown.js +1 -2
  4. package/dash_core_components/async-dropdown.js.map +1 -1
  5. package/dash_core_components/async-graph.js +1 -1
  6. package/dash_core_components/async-graph.js.map +1 -1
  7. package/dash_core_components/async-highlight.js +1 -1
  8. package/dash_core_components/async-highlight.js.map +1 -1
  9. package/dash_core_components/async-markdown.js +1 -1
  10. package/dash_core_components/async-markdown.js.map +1 -1
  11. package/dash_core_components/async-mathjax.js +1 -1
  12. package/dash_core_components/async-slider.js +1 -1
  13. package/dash_core_components/async-slider.js.map +1 -1
  14. package/dash_core_components/async-upload.js +1 -1
  15. package/dash_core_components/async-upload.js.map +1 -1
  16. package/dash_core_components/dash_core_components-shared.js +1 -1
  17. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  18. package/dash_core_components/dash_core_components.js +1 -1
  19. package/dash_core_components/dash_core_components.js.map +1 -1
  20. package/dash_core_components/proptypes.js +209 -6
  21. package/lib/components/Checklist.tsx +67 -0
  22. package/lib/components/Clipboard.react.js +1 -1
  23. package/lib/components/DatePickerRange.tsx +70 -0
  24. package/lib/components/DatePickerSingle.tsx +72 -0
  25. package/lib/components/Dropdown.tsx +19 -3
  26. package/lib/components/Input.tsx +1 -1
  27. package/lib/components/Loading.tsx +185 -0
  28. package/lib/components/RadioItems.tsx +69 -0
  29. package/lib/components/RangeSlider.tsx +5 -1
  30. package/lib/components/Slider.tsx +12 -1
  31. package/lib/components/Tab.tsx +19 -0
  32. package/lib/components/Tabs.tsx +311 -0
  33. package/lib/components/Textarea.tsx +79 -0
  34. package/lib/components/Tooltip.tsx +66 -0
  35. package/lib/components/css/calendar.css +66 -0
  36. package/lib/components/css/checklist.css +4 -0
  37. package/lib/components/css/datepickers.css +233 -0
  38. package/lib/components/css/dcc.css +3 -0
  39. package/lib/components/css/dropdown.css +34 -50
  40. package/lib/components/css/input.css +29 -7
  41. package/lib/components/css/optionslist.css +34 -0
  42. package/lib/components/css/radioitems.css +4 -0
  43. package/lib/components/css/sliders.css +33 -7
  44. package/lib/components/css/tabs.css +113 -0
  45. package/lib/components/css/textarea.css +21 -0
  46. package/lib/components/css/tooltip.css +127 -0
  47. package/lib/fragments/DatePickerRange.tsx +444 -0
  48. package/lib/fragments/DatePickerSingle.tsx +249 -0
  49. package/lib/fragments/Dropdown.tsx +212 -272
  50. package/lib/fragments/Graph.react.js +18 -45
  51. package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
  52. package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
  53. package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
  54. package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
  55. package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
  56. package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
  57. package/lib/fragments/Loading/types.ts +13 -0
  58. package/lib/fragments/RangeSlider.tsx +195 -63
  59. package/lib/index.ts +9 -11
  60. package/lib/types.ts +797 -132
  61. package/lib/utils/DatePickerPersistence.ts +14 -0
  62. package/lib/utils/LazyLoader/datePickerRange.ts +4 -0
  63. package/lib/utils/LazyLoader/datePickerSingle.ts +4 -0
  64. package/lib/utils/calendar/Calendar.tsx +382 -0
  65. package/lib/utils/calendar/CalendarDay.tsx +75 -0
  66. package/lib/utils/calendar/CalendarDayPadding.tsx +15 -0
  67. package/lib/utils/calendar/CalendarMonth.tsx +247 -0
  68. package/lib/utils/calendar/CalendarMonthHeader.tsx +23 -0
  69. package/lib/utils/calendar/createMonthGrid.ts +28 -0
  70. package/lib/utils/calendar/helpers.ts +272 -0
  71. package/lib/utils/computeSliderMarkers.ts +71 -116
  72. package/lib/utils/dropdownSearch.ts +4 -4
  73. package/lib/utils/optionRendering.tsx +175 -0
  74. package/lib/utils/optionTypes.ts +5 -5
  75. package/lib/utils/sliderRendering.tsx +63 -6
  76. package/package.json +16 -14
  77. package/lib/components/Checklist.react.js +0 -193
  78. package/lib/components/DatePickerRange.react.js +0 -244
  79. package/lib/components/DatePickerSingle.react.js +0 -209
  80. package/lib/components/Dropdown.react.js.old +0 -228
  81. package/lib/components/Input.react.js.old +0 -507
  82. package/lib/components/Loading.react.js +0 -254
  83. package/lib/components/RadioItems.react.js +0 -192
  84. package/lib/components/Slider.react.js.old +0 -214
  85. package/lib/components/Tab.react.js +0 -80
  86. package/lib/components/Tabs.react.js +0 -295
  87. package/lib/components/Textarea.react.js +0 -223
  88. package/lib/components/Textarea.react.js.old +0 -287
  89. package/lib/components/Tooltip.react.js +0 -120
  90. package/lib/components/css/Dropdown.css +0 -8
  91. package/lib/fragments/DatePickerRange.react.js +0 -188
  92. package/lib/fragments/DatePickerSingle.react.js +0 -132
  93. package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
  94. package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
  95. package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
  96. package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
  97. package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
  98. package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
  99. package/lib/utils/DatePickerPersistence.js +0 -18
  100. package/lib/utils/LazyLoader/datePickerRange.js +0 -8
  101. package/lib/utils/LazyLoader/datePickerSingle.js +0 -8
  102. package/lib/utils/convertToMoment.js +0 -30
  103. package/lib/utils/optionTypes.js +0 -39
@@ -17,68 +17,9 @@ import * as Popover from '@radix-ui/react-popover';
17
17
  import '../components/css/dropdown.css';
18
18
 
19
19
  import isEqual from 'react-fast-compare';
20
- import {DetailedDropdownOption, DropdownProps, DropdownValue} from '../types';
21
-
22
- interface DropdownOptionProps {
23
- index: number;
24
- option: DetailedDropdownOption;
25
- isSelected: boolean;
26
- onClick: (option: DetailedDropdownOption) => void;
27
- style?: React.CSSProperties;
28
- }
29
-
30
- function DropdownLabel(
31
- props: DetailedDropdownOption & {index: string | number}
32
- ): JSX.Element {
33
- const ctx = window.dash_component_api.useDashContext();
34
- const ExternalWrapper = window.dash_component_api.ExternalWrapper;
35
-
36
- if (typeof props.label === 'object') {
37
- return (
38
- <ExternalWrapper
39
- component={props.label}
40
- componentPath={[...ctx.componentPath, props.index]}
41
- />
42
- );
43
- }
44
- const displayLabel = `${props.label ?? props.value}`;
45
- return <span title={props.title}>{displayLabel}</span>;
46
- }
47
-
48
- const DropdownOption: React.FC<DropdownOptionProps> = ({
49
- option,
50
- isSelected,
51
- onClick,
52
- style,
53
- index,
54
- }) => {
55
- return (
56
- <label
57
- className={`dash-dropdown-option ${isSelected ? 'selected' : ''}`}
58
- role="option"
59
- aria-selected={isSelected}
60
- style={style}
61
- title={option.title}
62
- >
63
- <input
64
- type="checkbox"
65
- checked={isSelected}
66
- value={
67
- typeof option.value === 'boolean'
68
- ? `${option.value}`
69
- : option.value
70
- }
71
- disabled={!!option.disabled}
72
- onChange={() => onClick(option)}
73
- readOnly
74
- className="dash-dropdown-option-checkbox"
75
- />
76
- <span className="dash-dropdown-option-text">
77
- <DropdownLabel {...option} index={index} />
78
- </span>
79
- </label>
80
- );
81
- };
20
+ import {DetailedOption, DropdownProps, OptionValue} from '../types';
21
+ import {OptionsList, OptionLabel} from '../utils/optionRendering';
22
+ import uuid from 'uniqid';
82
23
 
83
24
  const Dropdown = (props: DropdownProps) => {
84
25
  const {
@@ -87,6 +28,7 @@ const Dropdown = (props: DropdownProps) => {
87
28
  closeOnSelect,
88
29
  clearable,
89
30
  disabled,
31
+ labels,
90
32
  maxHeight,
91
33
  multi,
92
34
  options,
@@ -97,14 +39,14 @@ const Dropdown = (props: DropdownProps) => {
97
39
  style,
98
40
  value,
99
41
  } = props;
100
- const [optionsCheck, setOptionsCheck] =
101
- useState<DetailedDropdownOption[]>();
42
+ const [optionsCheck, setOptionsCheck] = useState<DetailedOption[]>();
102
43
  const [isOpen, setIsOpen] = useState(false);
103
- const [displayOptions, setDisplayOptions] = useState<
104
- DetailedDropdownOption[]
105
- >([]);
44
+ const [displayOptions, setDisplayOptions] = useState<DetailedOption[]>([]);
106
45
  const persistentOptions = useRef<DropdownProps['options']>([]);
107
- const dropdownContainerRef = useRef<HTMLDivElement>(null);
46
+ const dropdownContainerRef = useRef<HTMLButtonElement>(null);
47
+ const dropdownContentRef = useRef<HTMLDivElement>(
48
+ document.createElement('div')
49
+ );
108
50
 
109
51
  const ctx = window.dash_component_api.useDashContext();
110
52
  const loading = ctx.useLoading();
@@ -123,7 +65,7 @@ const Dropdown = (props: DropdownProps) => {
123
65
  [persistentOptions.current, searchable, search_value]
124
66
  );
125
67
 
126
- const sanitizedValues: DropdownValue[] = useMemo(() => {
68
+ const sanitizedValues: OptionValue[] = useMemo(() => {
127
69
  if (value instanceof Array) {
128
70
  return value;
129
71
  }
@@ -133,54 +75,41 @@ const Dropdown = (props: DropdownProps) => {
133
75
  return [value];
134
76
  }, [value]);
135
77
 
136
- const toggleOption = useCallback(
137
- (option: DetailedDropdownOption) => {
138
- const isCurrentlySelected = sanitizedValues.includes(option.value);
139
-
140
- // Close dropdown if closeOnSelect is true (default behavior)
78
+ const updateSelection = useCallback(
79
+ (selection: OptionValue[]) => {
141
80
  if (closeOnSelect !== false) {
142
81
  setIsOpen(false);
143
82
  }
144
83
 
145
84
  if (multi) {
146
- let newValues: DropdownValue[];
147
-
148
- if (isCurrentlySelected) {
149
- // Deselecting: only allow if clearable is true or more than one option selected
150
- if (clearable || sanitizedValues.length > 1) {
151
- newValues = sanitizedValues.filter(
152
- v => v !== option.value
153
- );
154
- } else {
155
- // Cannot deselect the last option when clearable is false
156
- return;
85
+ // For multi-select, validate the selection respects clearable rules
86
+ if (selection.length === 0) {
87
+ // Empty selection: only allow if clearable is true
88
+ if (clearable) {
89
+ setProps({value: []});
157
90
  }
91
+ // If clearable is false and trying to set empty, do nothing
92
+ // return;
158
93
  } else {
159
- // Selecting: add to current selection
160
- newValues = [...sanitizedValues, option.value];
94
+ // Non-empty selection: always allowed in multi-select
95
+ setProps({value: selection});
161
96
  }
162
-
163
- setProps({value: newValues});
164
97
  } else {
165
- let newValue: DropdownValue | null;
166
-
167
- if (isCurrentlySelected) {
168
- // Deselecting: only allow if clearable is true
98
+ // For single-select, take the first value or null
99
+ if (selection.length === 0) {
100
+ // Empty selection: only allow if clearable is true
169
101
  if (clearable) {
170
- newValue = null;
171
- } else {
172
- // Cannot deselect when clearable is false
173
- return;
102
+ setProps({value: null});
174
103
  }
104
+ // If clearable is false and trying to set empty, do nothing
105
+ // return;
175
106
  } else {
176
- // Selecting: set as the single value
177
- newValue = option.value;
107
+ // Take the first value for single-select
108
+ setProps({value: selection[selection.length - 1]});
178
109
  }
179
-
180
- setProps({value: newValue});
181
110
  }
182
111
  },
183
- [multi, clearable, closeOnSelect, sanitizedValues]
112
+ [multi, clearable, closeOnSelect]
184
113
  );
185
114
 
186
115
  const onInputChange = useCallback(
@@ -227,10 +156,12 @@ const Dropdown = (props: DropdownProps) => {
227
156
  option => option.value === val
228
157
  );
229
158
  return (
230
- <React.Fragment key={`${option?.value}-${i}`}>
231
- {option && <DropdownLabel {...option} index={i} />}
232
- {i === sanitizedValues.length - 1 ? '' : ', '}
233
- </React.Fragment>
159
+ <span
160
+ key={`${option?.value}-${i}`}
161
+ className="dash-dropdown-value-item"
162
+ >
163
+ {option && <OptionLabel {...option} index={i} />}
164
+ </span>
234
165
  );
235
166
  });
236
167
  return labels;
@@ -245,13 +176,6 @@ const Dropdown = (props: DropdownProps) => {
245
176
  );
246
177
  }, [clearable, sanitizedValues, displayOptions, search_value]);
247
178
 
248
- const handleOptionClick = useCallback(
249
- (option: DetailedDropdownOption) => {
250
- toggleOption(option);
251
- },
252
- [toggleOption]
253
- );
254
-
255
179
  const handleClear = useCallback(() => {
256
180
  const finalValue: DropdownProps['value'] = multi ? [] : null;
257
181
  setProps({value: finalValue});
@@ -289,23 +213,46 @@ const Dropdown = (props: DropdownProps) => {
289
213
  // Update display options when filtered options or selection changes
290
214
  useEffect(() => {
291
215
  if (isOpen) {
292
- // Sort filtered options: selected first, then unselected
293
- const sortedOptions = [...filteredOptions].sort((a, b) => {
294
- const aSelected = sanitizedValues.includes(a.value);
295
- const bSelected = sanitizedValues.includes(b.value);
216
+ let sortedOptions = filteredOptions;
217
+ if (multi) {
218
+ // Sort filtered options: selected first, then unselected
219
+ sortedOptions = [...filteredOptions].sort((a, b) => {
220
+ const aSelected = sanitizedValues.includes(a.value);
221
+ const bSelected = sanitizedValues.includes(b.value);
296
222
 
297
- if (aSelected && !bSelected) {
298
- return -1;
299
- }
300
- if (!aSelected && bSelected) {
301
- return 1;
302
- }
303
- return 0; // Maintain original order within each group
304
- });
223
+ if (aSelected && !bSelected) {
224
+ return -1;
225
+ }
226
+ if (!aSelected && bSelected) {
227
+ return 1;
228
+ }
229
+ return 0; // Maintain original order within each group
230
+ });
231
+ }
305
232
 
306
233
  setDisplayOptions(sortedOptions);
307
234
  }
308
- }, [filteredOptions, isOpen]); // Removed sanitizedValues to prevent re-sorting on selection changes
235
+ }, [filteredOptions, isOpen]);
236
+
237
+ // Focus (and scroll) the first selected item when dropdown opens
238
+ useEffect(() => {
239
+ if (!isOpen || multi || search_value) {
240
+ return;
241
+ }
242
+
243
+ // waiting for the DOM to be ready after the dropdown renders
244
+ requestAnimationFrame(() => {
245
+ const selectedValue = sanitizedValues[0];
246
+
247
+ const selectedElement = dropdownContentRef.current.querySelector(
248
+ `.dash-options-list-option-checkbox[value="${selectedValue}"]`
249
+ );
250
+
251
+ if (selectedElement instanceof HTMLElement) {
252
+ selectedElement?.focus();
253
+ }
254
+ });
255
+ }, [isOpen, multi, displayOptions, sanitizedValues]);
309
256
 
310
257
  // Handle keyboard navigation in popover
311
258
  const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
@@ -381,10 +328,16 @@ const Dropdown = (props: DropdownProps) => {
381
328
 
382
329
  if (nextIndex > -1) {
383
330
  focusableElements[nextIndex].focus();
384
- focusableElements[nextIndex].scrollIntoView({
385
- behavior: 'auto',
386
- block: 'center',
387
- });
331
+ if (nextIndex === 0) {
332
+ // first element is a sticky search bar, so if we are focusing
333
+ // on that, also move the scroll to the top
334
+ dropdownContentRef.current?.scrollTo({top: 0});
335
+ } else {
336
+ focusableElements[nextIndex].scrollIntoView({
337
+ behavior: 'auto',
338
+ block: 'center',
339
+ });
340
+ }
388
341
  }
389
342
  }, []);
390
343
 
@@ -393,73 +346,61 @@ const Dropdown = (props: DropdownProps) => {
393
346
  (open: boolean) => {
394
347
  setIsOpen(open);
395
348
 
396
- if (open) {
397
- // Sort options: selected first, then unselected
398
- const selectedOptions: DetailedDropdownOption[] = [];
399
- const unselectedOptions: DetailedDropdownOption[] = [];
400
-
401
- // First, collect selected options in the order they appear in the `value` array
402
- sanitizedValues.forEach(value => {
403
- const option = filteredOptions.find(
404
- opt => opt.value === value
405
- );
406
- if (option) {
407
- selectedOptions.push(option);
408
- }
409
- });
410
-
411
- // Then, collect unselected options in the order they appear in `options` array
412
- filteredOptions.forEach(option => {
413
- if (!sanitizedValues.includes(option.value)) {
414
- unselectedOptions.push(option);
415
- }
416
- });
417
- const sortedOptions = [
418
- ...selectedOptions,
419
- ...unselectedOptions,
420
- ];
421
- setDisplayOptions(sortedOptions);
422
- } else {
349
+ if (!open) {
423
350
  setProps({search_value: undefined});
424
351
  }
425
352
  },
426
353
  [filteredOptions, sanitizedValues]
427
354
  );
428
355
 
356
+ const accessibleId = id ?? uuid();
357
+
429
358
  return (
430
- <div
431
- id={id}
432
- ref={dropdownContainerRef}
433
- className={`dash-dropdown ${className ?? ''}`}
434
- style={style}
435
- data-dash-is-loading={loading || undefined}
436
- >
437
- <Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
438
- <Popover.Trigger asChild>
439
- <button
440
- className="dash-dropdown-grid-container dash-dropdown-trigger"
441
- aria-label={props.placeholder}
442
- disabled={disabled}
443
- type="button"
444
- onKeyDown={e => {
445
- if (e.key === 'ArrowDown') {
446
- setIsOpen(true);
447
- }
448
- }}
449
- >
359
+ <Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
360
+ <Popover.Trigger asChild>
361
+ <button
362
+ id={id}
363
+ ref={dropdownContainerRef}
364
+ disabled={disabled}
365
+ type="button"
366
+ onKeyDown={e => {
367
+ if (e.key === 'ArrowDown') {
368
+ setIsOpen(true);
369
+ }
370
+ }}
371
+ className={`dash-dropdown ${className ?? ''}`}
372
+ style={style}
373
+ aria-labelledby={`${accessibleId}-value-count ${accessibleId}-value`}
374
+ aria-haspopup="listbox"
375
+ aria-expanded={isOpen}
376
+ data-dash-is-loading={loading || undefined}
377
+ >
378
+ <span className="dash-dropdown-grid-container dash-dropdown-trigger">
450
379
  {displayValue.length > 0 && (
451
- <span className="dash-dropdown-value">
380
+ <span
381
+ id={accessibleId + '-value'}
382
+ className="dash-dropdown-value"
383
+ >
452
384
  {displayValue}
453
385
  </span>
454
386
  )}
455
387
  {displayValue.length === 0 && (
456
- <span className="dash-dropdown-value dash-dropdown-placeholder">
388
+ <span
389
+ id={accessibleId + '-value'}
390
+ className="dash-dropdown-value dash-dropdown-placeholder"
391
+ >
457
392
  {props.placeholder}
458
393
  </span>
459
394
  )}
460
395
  {sanitizedValues.length > 1 && (
461
- <span className="dash-dropdown-value-count">
462
- {sanitizedValues.length} selected
396
+ <span
397
+ id={accessibleId + '-value-count'}
398
+ className="dash-dropdown-value-count"
399
+ >
400
+ {labels?.selected_count?.replace(
401
+ '{num_selected}',
402
+ `${sanitizedValues.length}`
403
+ )}
463
404
  </span>
464
405
  )}
465
406
  {clearable && !disabled && !!sanitizedValues.length && (
@@ -469,108 +410,107 @@ const Dropdown = (props: DropdownProps) => {
469
410
  e.preventDefault();
470
411
  handleClear();
471
412
  }}
472
- title="Clear selection"
473
- aria-label="Clear selection"
413
+ title={labels?.clear_selection}
414
+ aria-label={labels?.clear_selection}
474
415
  >
475
416
  <Cross1Icon />
476
417
  </a>
477
418
  )}
478
419
 
479
420
  <CaretDownIcon className="dash-dropdown-trigger-icon" />
480
- </button>
481
- </Popover.Trigger>
482
-
483
- <Popover.Portal container={dropdownContainerRef.current}>
484
- <Popover.Content
485
- className="dash-dropdown-content"
486
- align="start"
487
- sideOffset={5}
488
- onOpenAutoFocus={e => e.preventDefault()}
489
- onKeyDown={handleKeyDown}
490
- style={{
491
- maxHeight: maxHeight ? `${maxHeight}px` : 'auto',
492
- }}
493
- >
494
- {searchable && (
495
- <div className="dash-dropdown-grid-container dash-dropdown-search-container">
496
- <MagnifyingGlassIcon className="dash-dropdown-search-icon" />
497
- <input
498
- type="search"
499
- className="dash-dropdown-search"
500
- placeholder="Search"
501
- value={search_value || ''}
502
- autoComplete="off"
503
- onChange={e =>
504
- onInputChange(e.target.value)
505
- }
506
- autoFocus
507
- />
508
- {search_value && (
509
- <button
510
- type="button"
511
- className="dash-dropdown-clear"
512
- onClick={handleClearSearch}
513
- aria-label="Clear search"
514
- >
515
- <Cross1Icon />
516
- </button>
517
- )}
518
- </div>
519
- )}
520
- {multi && (
521
- <div className="dash-dropdown-actions">
421
+ </span>
422
+ </button>
423
+ </Popover.Trigger>
424
+
425
+ <Popover.Portal
426
+ // container is required otherwise popover will be rendered
427
+ // at document root, which may be outside of the Dash app (i.e.
428
+ // an embedded app)
429
+ container={dropdownContainerRef.current?.parentElement}
430
+ >
431
+ <Popover.Content
432
+ ref={dropdownContentRef}
433
+ className="dash-dropdown-content"
434
+ align="start"
435
+ sideOffset={5}
436
+ onOpenAutoFocus={e => e.preventDefault()}
437
+ onKeyDown={handleKeyDown}
438
+ style={{
439
+ maxHeight: maxHeight
440
+ ? `min(${maxHeight}px, calc(100vh - 100px))`
441
+ : 'calc(100vh - 100px)',
442
+ }}
443
+ >
444
+ {searchable && (
445
+ <div className="dash-dropdown-grid-container dash-dropdown-search-container">
446
+ <MagnifyingGlassIcon className="dash-dropdown-search-icon" />
447
+ <input
448
+ type="search"
449
+ className="dash-dropdown-search"
450
+ placeholder={labels?.search}
451
+ value={search_value || ''}
452
+ autoComplete="off"
453
+ onChange={e => onInputChange(e.target.value)}
454
+ autoFocus
455
+ />
456
+ {search_value && (
457
+ <button
458
+ type="button"
459
+ className="dash-dropdown-clear"
460
+ onClick={handleClearSearch}
461
+ aria-label={labels?.clear_search}
462
+ >
463
+ <Cross1Icon />
464
+ </button>
465
+ )}
466
+ </div>
467
+ )}
468
+ {multi && (
469
+ <div className="dash-dropdown-actions">
470
+ <button
471
+ type="button"
472
+ className="dash-dropdown-action-button"
473
+ onClick={handleSelectAll}
474
+ >
475
+ {labels?.select_all}
476
+ </button>
477
+ {canDeselectAll && (
522
478
  <button
523
479
  type="button"
524
480
  className="dash-dropdown-action-button"
525
- onClick={handleSelectAll}
481
+ onClick={handleDeselectAll}
526
482
  >
527
- Select All
483
+ {labels?.deselect_all}
528
484
  </button>
529
- {canDeselectAll && (
530
- <button
531
- type="button"
532
- className="dash-dropdown-action-button"
533
- onClick={handleDeselectAll}
534
- >
535
- Deselect All
536
- </button>
537
- )}
538
- </div>
539
- )}
540
- {isOpen && (
541
- <div className="dash-dropdown-options">
542
- {displayOptions.map((option, i) => {
543
- const isSelected = multi
544
- ? sanitizedValues.includes(option.value)
545
- : value === option.value;
546
-
547
- return (
548
- <DropdownOption
549
- key={`${option.value}-${i}`}
550
- index={i}
551
- option={option}
552
- isSelected={isSelected}
553
- onClick={handleOptionClick}
554
- style={{
555
- height: optionHeight
556
- ? `${optionHeight}px`
557
- : undefined,
558
- }}
559
- />
560
- );
561
- })}
562
- {search_value &&
563
- displayOptions.length === 0 && (
564
- <span className="dash-dropdown-option">
565
- No options found
566
- </span>
567
- )}
568
- </div>
569
- )}
570
- </Popover.Content>
571
- </Popover.Portal>
572
- </Popover.Root>
573
- </div>
485
+ )}
486
+ </div>
487
+ )}
488
+ {isOpen && !!displayOptions.length && (
489
+ <>
490
+ <OptionsList
491
+ options={displayOptions}
492
+ selected={sanitizedValues}
493
+ onSelectionChange={updateSelection}
494
+ className="dash-dropdown-options"
495
+ optionClassName="dash-dropdown-option"
496
+ optionStyle={{
497
+ height: optionHeight
498
+ ? `${optionHeight}px`
499
+ : undefined,
500
+ }}
501
+ />
502
+ </>
503
+ )}
504
+ {isOpen && search_value && !displayOptions.length && (
505
+ <div className="dash-dropdown-options">
506
+ <span className="dash-dropdown-option">
507
+ {labels?.no_options_found}
508
+ </span>
509
+ </div>
510
+ )}
511
+ </Popover.Content>
512
+ </Popover.Portal>
513
+ </Popover.Root>
574
514
  );
575
515
  };
576
516