dash-core-components 4.0.0-rc6 → 4.1.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.
- 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 -1
- 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 -2
- 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 +3 -0
- package/lib/components/Checklist.tsx +1 -1
- package/lib/components/Clipboard.react.js +67 -105
- package/lib/components/ConfirmDialog.react.js +6 -5
- package/lib/components/ConfirmDialogProvider.react.js +6 -5
- package/lib/components/Download.react.js +3 -1
- package/lib/components/Graph.react.js +5 -10
- package/lib/components/Interval.react.js +4 -3
- package/lib/components/Link.react.js +13 -10
- package/lib/components/Location.react.js +11 -7
- package/lib/components/Markdown.react.js +1 -8
- package/lib/components/RadioItems.tsx +1 -1
- package/lib/components/RangeSlider.tsx +2 -0
- package/lib/components/Slider.tsx +2 -0
- package/lib/components/Store.react.js +16 -13
- package/lib/components/css/calendar.css +20 -3
- package/lib/components/css/datepickers.css +9 -2
- package/lib/components/css/dropdown.css +12 -0
- package/lib/components/css/optionslist.css +0 -1
- package/lib/fragments/DatePickerRange.tsx +201 -140
- package/lib/fragments/DatePickerSingle.tsx +132 -108
- package/lib/fragments/Dropdown.tsx +202 -131
- package/lib/fragments/Graph.react.js +43 -40
- package/lib/fragments/Markdown.react.js +27 -38
- package/lib/fragments/RangeSlider.tsx +2 -0
- package/lib/fragments/Upload.react.js +117 -202
- package/lib/types.ts +17 -0
- package/lib/utils/LoadingElement.js +3 -2
- package/lib/utils/ResizeDetector.js +5 -3
- package/lib/utils/calendar/Calendar.tsx +1 -3
- package/lib/utils/calendar/cssVariables.ts +41 -0
- package/lib/utils/calendar/helpers.ts +1 -0
- package/lib/utils/dropdownSearch.ts +36 -45
- package/lib/utils/optionRendering.tsx +284 -43
- package/lib/utils/optionTypes.ts +25 -11
- package/package.json +9 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {isNil, without, isEmpty} from 'ramda';
|
|
1
|
+
import {isNil, without, append, isEmpty} from 'ramda';
|
|
2
2
|
import React, {
|
|
3
3
|
useState,
|
|
4
4
|
useCallback,
|
|
@@ -7,7 +7,7 @@ import React, {
|
|
|
7
7
|
useRef,
|
|
8
8
|
MouseEvent,
|
|
9
9
|
} from 'react';
|
|
10
|
-
import {
|
|
10
|
+
import {sanitizeDropdownOptions, filterOptions} from '../utils/dropdownSearch';
|
|
11
11
|
import {
|
|
12
12
|
CaretDownIcon,
|
|
13
13
|
MagnifyingGlassIcon,
|
|
@@ -18,7 +18,11 @@ import '../components/css/dropdown.css';
|
|
|
18
18
|
|
|
19
19
|
import isEqual from 'react-fast-compare';
|
|
20
20
|
import {DetailedOption, DropdownProps, OptionValue} from '../types';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
OptionsList,
|
|
23
|
+
OptionsListHandle,
|
|
24
|
+
OptionLabel,
|
|
25
|
+
} from '../utils/optionRendering';
|
|
22
26
|
import uuid from 'uniqid';
|
|
23
27
|
|
|
24
28
|
const Dropdown = (props: DropdownProps) => {
|
|
@@ -27,6 +31,7 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
27
31
|
className,
|
|
28
32
|
closeOnSelect,
|
|
29
33
|
clearable,
|
|
34
|
+
debounce,
|
|
30
35
|
disabled,
|
|
31
36
|
labels,
|
|
32
37
|
maxHeight,
|
|
@@ -42,44 +47,74 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
42
47
|
const [optionsCheck, setOptionsCheck] = useState<DetailedOption[]>();
|
|
43
48
|
const [isOpen, setIsOpen] = useState(false);
|
|
44
49
|
const [displayOptions, setDisplayOptions] = useState<DetailedOption[]>([]);
|
|
50
|
+
const [val, setVal] = useState<DropdownProps['value']>(value);
|
|
45
51
|
const persistentOptions = useRef<DropdownProps['options']>([]);
|
|
46
52
|
const dropdownContainerRef = useRef<HTMLButtonElement>(null);
|
|
47
53
|
const dropdownContentRef = useRef<HTMLDivElement>(
|
|
48
54
|
document.createElement('div')
|
|
49
55
|
);
|
|
50
56
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
57
|
+
const optionsListRef = useRef<OptionsListHandle>(null);
|
|
58
|
+
const focusedIndexRef = useRef(-1);
|
|
59
|
+
const pendingSearchRef = useRef('');
|
|
51
60
|
|
|
52
61
|
const ctx = window.dash_component_api.useDashContext();
|
|
53
62
|
const loading = ctx.useLoading();
|
|
54
63
|
|
|
64
|
+
// Sync val when external value prop changes
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!isEqual(value, val)) {
|
|
67
|
+
setVal(value);
|
|
68
|
+
}
|
|
69
|
+
}, [value]);
|
|
70
|
+
|
|
55
71
|
if (!persistentOptions || !isEqual(options, persistentOptions.current)) {
|
|
56
72
|
persistentOptions.current = options;
|
|
57
73
|
}
|
|
58
74
|
|
|
59
|
-
const
|
|
75
|
+
const sanitized = useMemo(
|
|
76
|
+
() => sanitizeDropdownOptions(persistentOptions.current),
|
|
77
|
+
[persistentOptions.current]
|
|
78
|
+
);
|
|
79
|
+
const sanitizedOptions = sanitized.options;
|
|
80
|
+
|
|
81
|
+
const filteredOptions = useMemo(
|
|
60
82
|
() =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
),
|
|
66
|
-
[persistentOptions.current, searchable, search_value]
|
|
83
|
+
searchable
|
|
84
|
+
? filterOptions(sanitized, search_value)
|
|
85
|
+
: sanitizedOptions,
|
|
86
|
+
[sanitized, searchable, search_value]
|
|
67
87
|
);
|
|
68
88
|
|
|
69
89
|
const sanitizedValues: OptionValue[] = useMemo(() => {
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
90
|
+
if (val instanceof Array) {
|
|
91
|
+
return val;
|
|
72
92
|
}
|
|
73
|
-
if (isNil(
|
|
93
|
+
if (isNil(val)) {
|
|
74
94
|
return [];
|
|
75
95
|
}
|
|
76
|
-
return [
|
|
77
|
-
}, [
|
|
96
|
+
return [val];
|
|
97
|
+
}, [val]);
|
|
98
|
+
|
|
99
|
+
const handleSetProps = useCallback(
|
|
100
|
+
(newValue: DropdownProps['value']) => {
|
|
101
|
+
if (debounce && isOpen) {
|
|
102
|
+
// local only
|
|
103
|
+
setVal(newValue);
|
|
104
|
+
} else {
|
|
105
|
+
setVal(newValue);
|
|
106
|
+
setProps({value: newValue});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
[debounce, isOpen, setProps]
|
|
110
|
+
);
|
|
78
111
|
|
|
79
112
|
const updateSelection = useCallback(
|
|
80
113
|
(selection: OptionValue[]) => {
|
|
81
114
|
if (closeOnSelect !== false) {
|
|
82
115
|
setIsOpen(false);
|
|
116
|
+
setProps({search_value: undefined});
|
|
117
|
+
pendingSearchRef.current = '';
|
|
83
118
|
}
|
|
84
119
|
|
|
85
120
|
if (multi) {
|
|
@@ -87,30 +122,28 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
87
122
|
if (selection.length === 0) {
|
|
88
123
|
// Empty selection: only allow if clearable is true
|
|
89
124
|
if (clearable) {
|
|
90
|
-
|
|
125
|
+
handleSetProps([]);
|
|
91
126
|
}
|
|
92
127
|
// If clearable is false and trying to set empty, do nothing
|
|
93
128
|
// return;
|
|
94
129
|
} else {
|
|
95
|
-
|
|
96
|
-
setProps({value: selection});
|
|
130
|
+
handleSetProps(selection);
|
|
97
131
|
}
|
|
98
132
|
} else {
|
|
99
133
|
// For single-select, take the first value or null
|
|
100
134
|
if (selection.length === 0) {
|
|
101
135
|
// Empty selection: only allow if clearable is true
|
|
102
136
|
if (clearable) {
|
|
103
|
-
|
|
137
|
+
handleSetProps(null);
|
|
104
138
|
}
|
|
105
139
|
// If clearable is false and trying to set empty, do nothing
|
|
106
140
|
// return;
|
|
107
141
|
} else {
|
|
108
|
-
|
|
109
|
-
setProps({value: selection[selection.length - 1]});
|
|
142
|
+
handleSetProps(selection[selection.length - 1]);
|
|
110
143
|
}
|
|
111
144
|
}
|
|
112
145
|
},
|
|
113
|
-
[multi, clearable, closeOnSelect]
|
|
146
|
+
[multi, clearable, closeOnSelect, handleSetProps]
|
|
114
147
|
);
|
|
115
148
|
|
|
116
149
|
const onInputChange = useCallback(
|
|
@@ -134,16 +167,16 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
134
167
|
!isNil(value) &&
|
|
135
168
|
!isEmpty(value)
|
|
136
169
|
) {
|
|
137
|
-
const
|
|
170
|
+
const {valueSet} = sanitized;
|
|
138
171
|
if (Array.isArray(value)) {
|
|
139
172
|
if (multi) {
|
|
140
|
-
const invalids = value.filter(v => !
|
|
173
|
+
const invalids = value.filter(v => !valueSet.has(v));
|
|
141
174
|
if (invalids.length) {
|
|
142
175
|
setProps({value: without(invalids, value)});
|
|
143
176
|
}
|
|
144
177
|
}
|
|
145
178
|
} else {
|
|
146
|
-
if (!
|
|
179
|
+
if (!valueSet.has(value)) {
|
|
147
180
|
setProps({value: null});
|
|
148
181
|
}
|
|
149
182
|
}
|
|
@@ -179,8 +212,8 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
179
212
|
|
|
180
213
|
const handleClear = useCallback(() => {
|
|
181
214
|
const finalValue: DropdownProps['value'] = multi ? [] : null;
|
|
182
|
-
|
|
183
|
-
}, [multi]);
|
|
215
|
+
handleSetProps(finalValue);
|
|
216
|
+
}, [multi, handleSetProps]);
|
|
184
217
|
|
|
185
218
|
const handleSelectAll = useCallback(() => {
|
|
186
219
|
if (multi) {
|
|
@@ -189,12 +222,12 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
189
222
|
.filter(option => !sanitizedValues.includes(option.value))
|
|
190
223
|
.map(option => option.value)
|
|
191
224
|
);
|
|
192
|
-
|
|
225
|
+
handleSetProps(allValues);
|
|
193
226
|
}
|
|
194
227
|
if (closeOnSelect) {
|
|
195
228
|
setIsOpen(false);
|
|
196
229
|
}
|
|
197
|
-
}, [multi, displayOptions, sanitizedValues, closeOnSelect]);
|
|
230
|
+
}, [multi, displayOptions, sanitizedValues, closeOnSelect, handleSetProps]);
|
|
198
231
|
|
|
199
232
|
const handleDeselectAll = useCallback(() => {
|
|
200
233
|
if (multi) {
|
|
@@ -203,12 +236,12 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
203
236
|
displayOption => displayOption.value === option
|
|
204
237
|
);
|
|
205
238
|
});
|
|
206
|
-
|
|
239
|
+
handleSetProps(withDeselected);
|
|
207
240
|
}
|
|
208
241
|
if (closeOnSelect) {
|
|
209
242
|
setIsOpen(false);
|
|
210
243
|
}
|
|
211
|
-
}, [multi, displayOptions, sanitizedValues, closeOnSelect]);
|
|
244
|
+
}, [multi, displayOptions, sanitizedValues, closeOnSelect, handleSetProps]);
|
|
212
245
|
|
|
213
246
|
// Sort options when popover opens - selected options first
|
|
214
247
|
// Update display options when filtered options or selection changes
|
|
@@ -235,134 +268,137 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
235
268
|
}
|
|
236
269
|
}, [filteredOptions, isOpen]);
|
|
237
270
|
|
|
238
|
-
// Focus first selected item or search input when dropdown opens
|
|
271
|
+
// Focus first selected item or search input when dropdown opens.
|
|
272
|
+
// Depends on displayOptions so it fires after OptionsList is mounted.
|
|
239
273
|
useEffect(() => {
|
|
240
|
-
if (!isOpen ||
|
|
274
|
+
if (!isOpen || pendingSearchRef.current || !displayOptions.length) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Don't steal focus from the search input during search-driven
|
|
279
|
+
// re-renders (displayOptions changes while the user is typing).
|
|
280
|
+
if (document.activeElement === searchInputRef.current) {
|
|
241
281
|
return;
|
|
242
282
|
}
|
|
243
283
|
|
|
244
|
-
// waiting for the DOM to be ready after the dropdown renders
|
|
245
284
|
requestAnimationFrame(() => {
|
|
246
|
-
// Try to focus the first selected item (for single-select)
|
|
247
285
|
if (!multi) {
|
|
248
286
|
const selectedValue = sanitizedValues[0];
|
|
249
287
|
if (selectedValue) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
selectedElement.focus();
|
|
288
|
+
const selectedIndex = displayOptions.findIndex(
|
|
289
|
+
o => o.value === selectedValue
|
|
290
|
+
);
|
|
291
|
+
if (selectedIndex >= 0) {
|
|
292
|
+
focusedIndexRef.current = selectedIndex;
|
|
293
|
+
optionsListRef.current?.focusItem(selectedIndex);
|
|
257
294
|
return;
|
|
258
295
|
}
|
|
259
296
|
}
|
|
260
297
|
}
|
|
261
298
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
299
|
+
if (searchable) {
|
|
300
|
+
searchInputRef.current?.focus();
|
|
301
|
+
} else {
|
|
302
|
+
focusedIndexRef.current = 0;
|
|
303
|
+
optionsListRef.current?.focusItem(0);
|
|
265
304
|
}
|
|
266
305
|
});
|
|
267
306
|
}, [isOpen, multi, displayOptions]);
|
|
268
307
|
|
|
269
|
-
// Handle keyboard navigation in popover
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (
|
|
285
|
-
['Home', 'End'].includes(e.key) &&
|
|
286
|
-
document.activeElement === searchInputRef.current
|
|
287
|
-
) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
308
|
+
// Handle keyboard navigation in popover.
|
|
309
|
+
// Index -1 = search input, 0..N-1 = option index in displayOptions.
|
|
310
|
+
const handleKeyDown = useCallback(
|
|
311
|
+
(e: React.KeyboardEvent) => {
|
|
312
|
+
const relevantKeys = [
|
|
313
|
+
'ArrowDown',
|
|
314
|
+
'ArrowUp',
|
|
315
|
+
'PageDown',
|
|
316
|
+
'PageUp',
|
|
317
|
+
'Home',
|
|
318
|
+
'End',
|
|
319
|
+
];
|
|
320
|
+
if (!relevantKeys.includes(e.key)) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
290
323
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
324
|
+
if (
|
|
325
|
+
['Home', 'End'].includes(e.key) &&
|
|
326
|
+
document.activeElement === searchInputRef.current
|
|
327
|
+
) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
294
330
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
331
|
+
if (displayOptions.length === 0) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
299
334
|
|
|
300
|
-
|
|
335
|
+
e.preventDefault();
|
|
336
|
+
|
|
337
|
+
const hasSearch = !!searchable;
|
|
338
|
+
const current = focusedIndexRef.current;
|
|
339
|
+
const maxIndex = displayOptions.length - 1;
|
|
340
|
+
const minIndex = hasSearch ? -1 : 0;
|
|
341
|
+
let nextIndex: number;
|
|
342
|
+
|
|
343
|
+
switch (e.key) {
|
|
344
|
+
case 'ArrowDown':
|
|
345
|
+
nextIndex = current < maxIndex ? current + 1 : minIndex;
|
|
346
|
+
break;
|
|
347
|
+
case 'ArrowUp':
|
|
348
|
+
nextIndex = current > minIndex ? current - 1 : maxIndex;
|
|
349
|
+
break;
|
|
350
|
+
case 'PageDown':
|
|
351
|
+
nextIndex = Math.min(current + 10, maxIndex);
|
|
352
|
+
break;
|
|
353
|
+
case 'PageUp':
|
|
354
|
+
nextIndex = Math.max(current - 10, minIndex);
|
|
355
|
+
break;
|
|
356
|
+
case 'Home':
|
|
357
|
+
nextIndex = minIndex;
|
|
358
|
+
break;
|
|
359
|
+
case 'End':
|
|
360
|
+
nextIndex = maxIndex;
|
|
361
|
+
break;
|
|
362
|
+
default:
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
301
365
|
|
|
302
|
-
|
|
303
|
-
document.activeElement as HTMLElement
|
|
304
|
-
);
|
|
305
|
-
let nextIndex = -1;
|
|
306
|
-
|
|
307
|
-
switch (e.key) {
|
|
308
|
-
case 'ArrowDown':
|
|
309
|
-
nextIndex =
|
|
310
|
-
currentIndex < focusableElements.length - 1
|
|
311
|
-
? currentIndex + 1
|
|
312
|
-
: 0;
|
|
313
|
-
break;
|
|
314
|
-
|
|
315
|
-
case 'ArrowUp':
|
|
316
|
-
nextIndex =
|
|
317
|
-
currentIndex > 0
|
|
318
|
-
? currentIndex - 1
|
|
319
|
-
: focusableElements.length - 1;
|
|
320
|
-
|
|
321
|
-
break;
|
|
322
|
-
case 'PageDown':
|
|
323
|
-
nextIndex = Math.min(
|
|
324
|
-
currentIndex + 10,
|
|
325
|
-
focusableElements.length - 1
|
|
326
|
-
);
|
|
327
|
-
break;
|
|
328
|
-
case 'PageUp':
|
|
329
|
-
nextIndex = Math.max(currentIndex - 10, 0);
|
|
330
|
-
break;
|
|
331
|
-
case 'Home':
|
|
332
|
-
nextIndex = 0;
|
|
333
|
-
break;
|
|
334
|
-
case 'End':
|
|
335
|
-
nextIndex = focusableElements.length - 1;
|
|
336
|
-
break;
|
|
337
|
-
default:
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
366
|
+
focusedIndexRef.current = nextIndex;
|
|
340
367
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (nextIndex === 0) {
|
|
344
|
-
// first element is a sticky search bar, so if we are focusing
|
|
345
|
-
// on that, also move the scroll to the top
|
|
368
|
+
if (nextIndex === -1) {
|
|
369
|
+
searchInputRef.current?.focus();
|
|
346
370
|
dropdownContentRef.current?.scrollTo({top: 0});
|
|
347
371
|
} else {
|
|
348
|
-
|
|
349
|
-
behavior: 'auto',
|
|
350
|
-
block: 'nearest',
|
|
351
|
-
});
|
|
372
|
+
optionsListRef.current?.focusItem(nextIndex);
|
|
352
373
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
374
|
+
},
|
|
375
|
+
[displayOptions.length, searchable]
|
|
376
|
+
);
|
|
355
377
|
|
|
356
|
-
// Handle popover open/close
|
|
357
378
|
const handleOpenChange = useCallback(
|
|
358
379
|
(open: boolean) => {
|
|
359
380
|
setIsOpen(open);
|
|
381
|
+
focusedIndexRef.current = -1;
|
|
360
382
|
|
|
361
383
|
if (!open) {
|
|
362
|
-
|
|
384
|
+
pendingSearchRef.current = '';
|
|
385
|
+
const updates: Partial<DropdownProps> = {};
|
|
386
|
+
|
|
387
|
+
if (!isNil(search_value)) {
|
|
388
|
+
updates.search_value = undefined;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Commit debounced value on close only
|
|
392
|
+
if (debounce && !isEqual(value, val)) {
|
|
393
|
+
updates.value = val;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (Object.keys(updates).length > 0) {
|
|
397
|
+
setProps(updates);
|
|
398
|
+
}
|
|
363
399
|
}
|
|
364
400
|
},
|
|
365
|
-
[
|
|
401
|
+
[debounce, value, val, search_value, setProps]
|
|
366
402
|
);
|
|
367
403
|
|
|
368
404
|
const accessibleId = id ?? uuid();
|
|
@@ -392,6 +428,14 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
392
428
|
) {
|
|
393
429
|
handleClear();
|
|
394
430
|
}
|
|
431
|
+
if (e.key.length === 1 && searchable) {
|
|
432
|
+
pendingSearchRef.current += e.key;
|
|
433
|
+
setProps({search_value: pendingSearchRef.current});
|
|
434
|
+
setIsOpen(true);
|
|
435
|
+
requestAnimationFrame(() =>
|
|
436
|
+
searchInputRef.current?.focus()
|
|
437
|
+
);
|
|
438
|
+
}
|
|
395
439
|
}}
|
|
396
440
|
className={`dash-dropdown ${className ?? ''}`}
|
|
397
441
|
aria-labelledby={`${accessibleId}-value-count ${accessibleId}-value`}
|
|
@@ -475,6 +519,31 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
475
519
|
value={search_value || ''}
|
|
476
520
|
autoComplete="off"
|
|
477
521
|
onChange={e => onInputChange(e.target.value)}
|
|
522
|
+
onKeyUp={e => {
|
|
523
|
+
if (
|
|
524
|
+
!search_value ||
|
|
525
|
+
e.key !== 'Enter' ||
|
|
526
|
+
!displayOptions.length
|
|
527
|
+
) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const firstVal = displayOptions[0].value;
|
|
531
|
+
const isSelected =
|
|
532
|
+
sanitizedValues.includes(firstVal);
|
|
533
|
+
let newSelection;
|
|
534
|
+
if (isSelected) {
|
|
535
|
+
newSelection = without(
|
|
536
|
+
[firstVal],
|
|
537
|
+
sanitizedValues
|
|
538
|
+
);
|
|
539
|
+
} else {
|
|
540
|
+
newSelection = append(
|
|
541
|
+
firstVal,
|
|
542
|
+
sanitizedValues
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
updateSelection(newSelection);
|
|
546
|
+
}}
|
|
478
547
|
ref={searchInputRef}
|
|
479
548
|
/>
|
|
480
549
|
{search_value && (
|
|
@@ -512,17 +581,19 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
512
581
|
{isOpen && !!displayOptions.length && (
|
|
513
582
|
<>
|
|
514
583
|
<OptionsList
|
|
584
|
+
ref={optionsListRef}
|
|
515
585
|
options={displayOptions}
|
|
516
586
|
selected={sanitizedValues}
|
|
517
587
|
onSelectionChange={updateSelection}
|
|
518
588
|
inputType={multi ? 'checkbox' : 'radio'}
|
|
519
589
|
className="dash-dropdown-options"
|
|
520
590
|
optionClassName="dash-dropdown-option"
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
?
|
|
524
|
-
: undefined
|
|
525
|
-
}
|
|
591
|
+
optionHeight={
|
|
592
|
+
typeof optionHeight === 'number'
|
|
593
|
+
? optionHeight
|
|
594
|
+
: undefined
|
|
595
|
+
}
|
|
596
|
+
maxHeight={maxHeight}
|
|
526
597
|
/>
|
|
527
598
|
</>
|
|
528
599
|
)}
|
|
@@ -17,13 +17,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
19
19
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
20
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
21
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
22
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
24
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
25
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
26
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /* global Plotly:true */
|
|
20
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* global Plotly:true */
|
|
27
21
|
/**
|
|
28
22
|
* `autosize: true` causes Plotly.js to conform to the parent element size.
|
|
29
23
|
* This is necessary for `dcc.Graph` call to `Plotly.Plots.resize(target)` to do something.
|
|
@@ -155,12 +149,16 @@ class PlotlyGraph extends _react.Component {
|
|
|
155
149
|
}
|
|
156
150
|
plot(props) {
|
|
157
151
|
var _figure, _figure2, _figure3;
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
var {
|
|
153
|
+
figure,
|
|
154
|
+
config
|
|
155
|
+
} = props;
|
|
156
|
+
var {
|
|
157
|
+
animate,
|
|
158
|
+
animation_options,
|
|
159
|
+
responsive,
|
|
160
|
+
mathjax
|
|
161
|
+
} = props;
|
|
164
162
|
var gd = this.gd.current;
|
|
165
163
|
figure = props._dashprivate_transformFigure(figure, gd);
|
|
166
164
|
config = props._dashprivate_transformConfig(config, gd);
|
|
@@ -211,10 +209,14 @@ class PlotlyGraph extends _react.Component {
|
|
|
211
209
|
});
|
|
212
210
|
}
|
|
213
211
|
amendTraces(p, oldProps, newProps) {
|
|
214
|
-
var
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
var {
|
|
213
|
+
prependData: oldPrepend,
|
|
214
|
+
extendData: oldExtend
|
|
215
|
+
} = oldProps;
|
|
216
|
+
var {
|
|
217
|
+
prependData: newPrepend,
|
|
218
|
+
extendData: newExtend
|
|
219
|
+
} = newProps;
|
|
218
220
|
var _this = this;
|
|
219
221
|
function mergeTraces(props, dataKey, plotlyFnKey) {
|
|
220
222
|
var clearState = props.clearState;
|
|
@@ -223,10 +225,7 @@ class PlotlyGraph extends _react.Component {
|
|
|
223
225
|
dataArray.forEach(data => {
|
|
224
226
|
var updateData, traceIndices, maxPoints;
|
|
225
227
|
if (Array.isArray(data) && typeof data[0] === 'object') {
|
|
226
|
-
|
|
227
|
-
updateData = _data[0];
|
|
228
|
-
traceIndices = _data[1];
|
|
229
|
-
maxPoints = _data[2];
|
|
228
|
+
[updateData, traceIndices, maxPoints] = data;
|
|
230
229
|
} else {
|
|
231
230
|
updateData = data;
|
|
232
231
|
}
|
|
@@ -268,9 +267,10 @@ class PlotlyGraph extends _react.Component {
|
|
|
268
267
|
return layout;
|
|
269
268
|
}
|
|
270
269
|
var override = this.getLayoutOverride(responsive);
|
|
271
|
-
var
|
|
272
|
-
prev_override
|
|
273
|
-
prev_originals
|
|
270
|
+
var {
|
|
271
|
+
override: prev_override,
|
|
272
|
+
originals: prev_originals
|
|
273
|
+
} = this.state;
|
|
274
274
|
// Store the original data that we're about to override
|
|
275
275
|
var originals = {};
|
|
276
276
|
for (var key in override) {
|
|
@@ -317,9 +317,11 @@ class PlotlyGraph extends _react.Component {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
isResponsive(props) {
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
|
|
320
|
+
var {
|
|
321
|
+
config,
|
|
322
|
+
figure,
|
|
323
|
+
responsive
|
|
324
|
+
} = props;
|
|
323
325
|
if ((0, _ramda.type)(responsive) === 'Boolean') {
|
|
324
326
|
return responsive;
|
|
325
327
|
}
|
|
@@ -340,13 +342,14 @@ class PlotlyGraph extends _react.Component {
|
|
|
340
342
|
Plotly.Plots.resize(gd).catch(() => {}).finally(() => gd.classList.remove('dash-graph--pending'));
|
|
341
343
|
}
|
|
342
344
|
bindEvents() {
|
|
343
|
-
var
|
|
344
|
-
setProps
|
|
345
|
-
clear_on_unhover
|
|
346
|
-
relayoutData
|
|
347
|
-
restyleData
|
|
348
|
-
hoverData
|
|
349
|
-
selectedData
|
|
345
|
+
var {
|
|
346
|
+
setProps,
|
|
347
|
+
clear_on_unhover,
|
|
348
|
+
relayoutData,
|
|
349
|
+
restyleData,
|
|
350
|
+
hoverData,
|
|
351
|
+
selectedData
|
|
352
|
+
} = this.props;
|
|
350
353
|
var gd = this.gd.current;
|
|
351
354
|
gd.on('plotly_click', eventData => {
|
|
352
355
|
var clickData = filterEventData(gd, eventData, 'click');
|
|
@@ -444,12 +447,12 @@ class PlotlyGraph extends _react.Component {
|
|
|
444
447
|
}
|
|
445
448
|
}
|
|
446
449
|
render() {
|
|
447
|
-
var
|
|
448
|
-
className
|
|
449
|
-
id
|
|
450
|
-
loading_state
|
|
451
|
-
|
|
452
|
-
|
|
450
|
+
var {
|
|
451
|
+
className,
|
|
452
|
+
id,
|
|
453
|
+
loading_state,
|
|
454
|
+
style = {}
|
|
455
|
+
} = this.props;
|
|
453
456
|
if (this.isResponsive(this.props)) {
|
|
454
457
|
style.height || (style.height = '100%');
|
|
455
458
|
}
|