MCPcopy
hub / github.com/plotly/dash / Dropdown

Function Dropdown

components/dash-core-components/src/fragments/Dropdown.tsx:28–661  ·  view source on GitHub ↗
(props: DropdownProps)

Source from the content-addressed store, hash-verified

26import uuid from 'uniqid';
27
28const Dropdown = (props: DropdownProps) => {
29 const {
30 id,
31 className,
32 closeOnSelect,
33 clearable,
34 debounce,
35 disabled,
36 labels,
37 maxHeight,
38 multi,
39 options,
40 optionHeight,
41 setProps,
42 searchable,
43 search_value,
44 search_order,
45 style,
46 value,
47 } = props;
48 const [optionsCheck, setOptionsCheck] = useState<DetailedOption[]>();
49 const [isOpen, setIsOpen] = useState(false);
50 const [displayOptions, setDisplayOptions] = useState<DetailedOption[]>([]);
51 const [val, setVal] = useState<DropdownProps['value']>(value);
52 const persistentOptions = useRef<DropdownProps['options']>([]);
53 const dropdownContainerRef = useRef<HTMLButtonElement>(null);
54 const dropdownContentRef = useRef<HTMLDivElement>(
55 document.createElement('div')
56 );
57 const searchInputRef = useRef<HTMLInputElement>(null);
58 const optionsListRef = useRef<OptionsListHandle>(null);
59 const focusedIndexRef = useRef(-1);
60 const pendingSearchRef = useRef('');
61
62 const ctx = window.dash_component_api.useDashContext();
63 const loading = ctx.useLoading();
64
65 // Sync val when external value prop changes
66 useEffect(() => {
67 if (!isEqual(value, val)) {
68 setVal(value);
69 }
70 }, [value]);
71
72 if (!persistentOptions || !isEqual(options, persistentOptions.current)) {
73 persistentOptions.current = options;
74 }
75
76 const sanitized = useMemo(
77 () => sanitizeDropdownOptions(persistentOptions.current),
78 [persistentOptions.current]
79 );
80 const sanitizedOptions = sanitized.options;
81
82 const filteredOptions = useMemo(
83 () =>
84 searchable
85 ? filterOptions(sanitized, search_value, search_order)

Callers

nothing calls this directly

Calls 15

useStateFunction · 0.90
useRefFunction · 0.90
useEffectFunction · 0.90
useMemoFunction · 0.90
sanitizeDropdownOptionsFunction · 0.90
filterOptionsFunction · 0.90
useCallbackFunction · 0.90
isEqualFunction · 0.85
isEmptyFunction · 0.85
filterMethod · 0.80
findMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…