Skip to content

Commit

Permalink
Fix #4489: Dropdown add getVirtualScroller (#4491)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Jun 7, 2023
1 parent 51d856d commit 8adf29c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Dropdown = React.memo(
const overlayRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);
const focusInputRef = React.useRef(props.focusInputRef);
const virtualScrollerRef = React.useRef(null);
const searchTimeout = React.useRef(null);
const searchValue = React.useRef(null);
const currentSearchChar = React.useRef(null);
Expand Down Expand Up @@ -621,7 +622,8 @@ export const Dropdown = React.memo(
getElement: () => elementRef.current,
getOverlay: () => overlayRef.current,
getInput: () => inputRef.current,
getFocusInput: () => focusInputRef.current
getFocusInput: () => focusInputRef.current,
getVirtualScroller: () => virtualScrollerRef.current
}));

React.useEffect(() => {
Expand Down Expand Up @@ -875,6 +877,7 @@ export const Dropdown = React.memo(
<DropdownPanel
ref={overlayRef}
visibleOptions={visibleOptions}
virtualScrollerRef={virtualScrollerRef}
{...props}
appendTo={appendTo}
onClick={onPanelClick}
Expand Down
9 changes: 4 additions & 5 deletions components/lib/dropdown/DropdownPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { DropdownItem } from './DropdownItem';
export const DropdownPanel = React.memo(
React.forwardRef((props, ref) => {
const ptm = props.ptm;
const virtualScrollerRef = React.useRef(null);
const filterInputRef = React.useRef(null);
const isEmptyFilter = !(props.visibleOptions && props.visibleOptions.length) && props.hasFilter;
const filterOptions = {
Expand All @@ -21,11 +20,11 @@ export const DropdownPanel = React.memo(

const onEnter = () => {
props.onEnter(() => {
if (virtualScrollerRef.current) {
if (props.virtualScrollerRef.current) {
const selectedIndex = props.getSelectedOptionIndex();

if (selectedIndex !== -1) {
setTimeout(() => virtualScrollerRef.current.scrollToIndex(selectedIndex), 0);
setTimeout(() => props.virtualScrollerRef.current.scrollToIndex(selectedIndex), 0);
}
}
});
Expand All @@ -40,7 +39,7 @@ export const DropdownPanel = React.memo(
};

const onFilterInputChange = (event) => {
virtualScrollerRef.current && virtualScrollerRef.current.scrollToIndex(0);
props.virtualScrollerRef.current && props.virtualScrollerRef.current.scrollToIndex(0);
props.onFilterInputChange && props.onFilterInputChange(event);
};

Expand Down Expand Up @@ -242,7 +241,7 @@ export const DropdownPanel = React.memo(
}
};

return <VirtualScroller ref={virtualScrollerRef} {...virtualScrollerProps} pt={ptm('virtualScroller')} />;
return <VirtualScroller ref={props.virtualScrollerRef} {...virtualScrollerProps} pt={ptm('virtualScroller')} />;
} else {
const items = createItems();
const wrapperProps = mergeProps(
Expand Down

0 comments on commit 8adf29c

Please sign in to comment.