Skip to content

Commit fc2d1e1

Browse files
author
lhy
committed
fix default no go top
1 parent f6dcc70 commit fc2d1e1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/OptionList/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const RawOptionList = React.forwardRef<RefOptionListProps, RawOptionListProps>((
173173
`li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes
174174
);
175175
if (ele) {
176-
scrollIntoParentView(ele);
176+
scrollIntoParentView(ele, activeValueCells);
177177
}
178178
}
179179
}, [activeValueCells]);

src/utils/commonUtil.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function isLeaf(option: DefaultOptionType, fieldNames: FieldNames) {
4444
return option.isLeaf ?? !option[fieldNames.children]?.length;
4545
}
4646

47-
export function scrollIntoParentView(element: HTMLElement) {
47+
export function scrollIntoParentView(element: HTMLElement, activeValueCells: React.Key[]) {
4848
const parent = element.parentElement;
4949
if (!parent) {
5050
return;
@@ -55,6 +55,13 @@ export function scrollIntoParentView(element: HTMLElement) {
5555
parent.scrollTo({ top: elementToParent });
5656
} else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) {
5757
parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight });
58+
} else {
59+
const parentContainerSiblings = parent.parentElement.children;
60+
if (!activeValueCells.length || activeValueCells.length === parentContainerSiblings.length) return
61+
const container = parentContainerSiblings[activeValueCells.length];
62+
if (container && typeof container.scrollTo === 'function') {
63+
container.scrollTo({ top: 0 });
64+
}
5865
}
5966
}
6067

0 commit comments

Comments
 (0)