Files
ncd-fe/packages/nicolium/src/utils/scroll-utils.ts
nicole mikołajczyk 05b44067c2 nicolium: apply this hotkey thing to new timeline
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2026-03-05 10:54:38 +01:00

40 lines
991 B
TypeScript

import type React from 'react';
import type { VirtuosoHandle } from 'react-virtuoso';
const selectChild = (
index: number,
handle: React.RefObject<VirtuosoHandle | null>,
node: ParentNode = document,
count?: number,
align?: 'start' | 'center' | 'end',
) => {
if (index < 0) return false;
if (count !== undefined && index === count) {
const loadMoreButton = node.querySelector<HTMLButtonElement>('.⁂-load-more');
if (loadMoreButton) {
loadMoreButton.focus({ preventScroll: false });
return;
}
return false;
}
const selector = `[data-index="${index}"] .focusable`;
const element = node.querySelector<HTMLDivElement>(selector);
if (element) {
element.focus({ preventScroll: false });
} else {
handle.current?.scrollIntoView({
index,
behavior: 'smooth',
done: () => {
if (!element) document.querySelector<HTMLDivElement>(selector)?.focus();
},
align,
});
}
};
export { selectChild };