Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OptionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const RefOptionList = React.forwardRef<RefOptionListProps>((props, ref) => {
`li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes
);
if (ele) {
scrollIntoParentView(ele);
scrollIntoParentView(ele, activeValueCells);
}
}
}, [activeValueCells]);
Expand Down
9 changes: 8 additions & 1 deletion src/utils/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function isLeaf(option: DefaultOptionType, fieldNames: FieldNames) {
return option.isLeaf ?? !option[fieldNames.children]?.length;
}

export function scrollIntoParentView(element: HTMLElement) {
export function scrollIntoParentView(element: HTMLElement, activeValueCells: React.Key[]) {
const parent = element.parentElement;
if (!parent) {
return;
Expand All @@ -54,6 +54,13 @@ export function scrollIntoParentView(element: HTMLElement) {
parent.scrollTo({ top: elementToParent });
} else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) {
parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight });
} else {
const parentToContainer = parent.parentElement.children;
if(!activeValueCells.length || activeValueCells.length === parentToContainer.length) return
const container = parentToContainer[activeValueCells.length];
if (container && typeof container.scrollTo === 'function') {
container.scrollTo({top: 0});
}
}
}

Expand Down