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.
- package/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -2
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-graph.js.map +1 -1
- package/dash_core_components/async-highlight.js +1 -1
- package/dash_core_components/async-highlight.js.map +1 -1
- package/dash_core_components/async-markdown.js +1 -1
- package/dash_core_components/async-markdown.js.map +1 -1
- package/dash_core_components/async-mathjax.js +1 -1
- package/dash_core_components/async-slider.js +1 -1
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/async-upload.js +1 -1
- package/dash_core_components/async-upload.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/dash_core_components/proptypes.js +209 -6
- package/lib/components/Checklist.tsx +67 -0
- package/lib/components/Clipboard.react.js +1 -1
- package/lib/components/DatePickerRange.tsx +70 -0
- package/lib/components/DatePickerSingle.tsx +72 -0
- package/lib/components/Dropdown.tsx +19 -3
- package/lib/components/Input.tsx +1 -1
- package/lib/components/Loading.tsx +185 -0
- package/lib/components/RadioItems.tsx +69 -0
- package/lib/components/RangeSlider.tsx +5 -1
- package/lib/components/Slider.tsx +12 -1
- package/lib/components/Tab.tsx +19 -0
- package/lib/components/Tabs.tsx +311 -0
- package/lib/components/Textarea.tsx +79 -0
- package/lib/components/Tooltip.tsx +66 -0
- package/lib/components/css/calendar.css +66 -0
- package/lib/components/css/checklist.css +4 -0
- package/lib/components/css/datepickers.css +233 -0
- package/lib/components/css/dcc.css +3 -0
- package/lib/components/css/dropdown.css +34 -50
- package/lib/components/css/input.css +29 -7
- package/lib/components/css/optionslist.css +34 -0
- package/lib/components/css/radioitems.css +4 -0
- package/lib/components/css/sliders.css +33 -7
- package/lib/components/css/tabs.css +113 -0
- package/lib/components/css/textarea.css +21 -0
- package/lib/components/css/tooltip.css +127 -0
- package/lib/fragments/DatePickerRange.tsx +444 -0
- package/lib/fragments/DatePickerSingle.tsx +249 -0
- package/lib/fragments/Dropdown.tsx +212 -272
- package/lib/fragments/Graph.react.js +18 -45
- package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
- package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
- package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
- package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
- package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
- package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
- package/lib/fragments/Loading/types.ts +13 -0
- package/lib/fragments/RangeSlider.tsx +195 -63
- package/lib/index.ts +9 -11
- package/lib/types.ts +797 -132
- package/lib/utils/DatePickerPersistence.ts +14 -0
- package/lib/utils/LazyLoader/datePickerRange.ts +4 -0
- package/lib/utils/LazyLoader/datePickerSingle.ts +4 -0
- package/lib/utils/calendar/Calendar.tsx +382 -0
- package/lib/utils/calendar/CalendarDay.tsx +75 -0
- package/lib/utils/calendar/CalendarDayPadding.tsx +15 -0
- package/lib/utils/calendar/CalendarMonth.tsx +247 -0
- package/lib/utils/calendar/CalendarMonthHeader.tsx +23 -0
- package/lib/utils/calendar/createMonthGrid.ts +28 -0
- package/lib/utils/calendar/helpers.ts +272 -0
- package/lib/utils/computeSliderMarkers.ts +71 -116
- package/lib/utils/dropdownSearch.ts +4 -4
- package/lib/utils/optionRendering.tsx +175 -0
- package/lib/utils/optionTypes.ts +5 -5
- package/lib/utils/sliderRendering.tsx +63 -6
- package/package.json +16 -14
- package/lib/components/Checklist.react.js +0 -193
- package/lib/components/DatePickerRange.react.js +0 -244
- package/lib/components/DatePickerSingle.react.js +0 -209
- package/lib/components/Dropdown.react.js.old +0 -228
- package/lib/components/Input.react.js.old +0 -507
- package/lib/components/Loading.react.js +0 -254
- package/lib/components/RadioItems.react.js +0 -192
- package/lib/components/Slider.react.js.old +0 -214
- package/lib/components/Tab.react.js +0 -80
- package/lib/components/Tabs.react.js +0 -295
- package/lib/components/Textarea.react.js +0 -223
- package/lib/components/Textarea.react.js.old +0 -287
- package/lib/components/Tooltip.react.js +0 -120
- package/lib/components/css/Dropdown.css +0 -8
- package/lib/fragments/DatePickerRange.react.js +0 -188
- package/lib/fragments/DatePickerSingle.react.js +0 -132
- package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
- package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
- package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
- package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
- package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
- package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
- package/lib/utils/DatePickerPersistence.js +0 -18
- package/lib/utils/LazyLoader/datePickerRange.js +0 -8
- package/lib/utils/LazyLoader/datePickerSingle.js +0 -8
- package/lib/utils/convertToMoment.js +0 -30
- 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 {
|
|
21
|
-
|
|
22
|
-
|
|
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<
|
|
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:
|
|
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
|
|
137
|
-
(
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
//
|
|
160
|
-
|
|
94
|
+
// Non-empty selection: always allowed in multi-select
|
|
95
|
+
setProps({value: selection});
|
|
161
96
|
}
|
|
162
|
-
|
|
163
|
-
setProps({value: newValues});
|
|
164
97
|
} else {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
177
|
-
|
|
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
|
|
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
|
-
<
|
|
231
|
-
{
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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]);
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
<
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
|
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
|
|
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
|
|
462
|
-
{
|
|
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=
|
|
473
|
-
aria-label=
|
|
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
|
-
</
|
|
481
|
-
</
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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={
|
|
481
|
+
onClick={handleDeselectAll}
|
|
526
482
|
>
|
|
527
|
-
|
|
483
|
+
{labels?.deselect_all}
|
|
528
484
|
</button>
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
|