(props: DropdownProps)
| 26 | import uuid from 'uniqid'; |
| 27 | |
| 28 | const 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…