+
{label}
{secondaryLabel && {secondaryLabel}}
@@ -474,11 +474,38 @@ const DropdownSubMenuWrapper =
({
selectType,
showIndex
}: DropdownSubMenuWrapperProps) => {
+ const subContentRef = React.useRef(null);
+ const [isOpen, setIsOpen] = React.useState(false);
+
+ const scrollToSelectedItem = React.useCallback(() => {
+ if (!subContentRef.current) return;
+
+ const selectedIndex = items?.findIndex((item) => (item as DropdownItem).selected);
+ if (selectedIndex === undefined || selectedIndex === -1) return;
+
+ const menuItems = subContentRef.current.querySelectorAll('[role="menuitem"]');
+ const selectedElement = menuItems[selectedIndex - 1];
+
+ if (selectedElement) {
+ selectedElement.scrollIntoView({ block: 'start', behavior: 'instant', inline: 'start' });
+ }
+ }, [items]);
+
+ useEffect(() => {
+ if (isOpen) {
+ const timeoutId = setTimeout(scrollToSelectedItem, 70);
+ return () => clearTimeout(timeoutId);
+ }
+ }, [isOpen, scrollToSelectedItem]);
+
return (
-
+
{children}
-
+
{items?.map((item, index) => (
{
}));
const { versions = [], version_number } = data || {};
+ const onClickVersionHistory = useMemoizedFn((versionNumber: number) => {
+ console.log('versionNumber', versionNumber);
+ });
+
const versionHistoryItems: DropdownItems = useMemo(() => {
return versions.map((x) => ({
label: `Version ${x.version_number}`,
secondaryLabel: timeFromNow(x.updated_at, false),
value: x.version_number.toString(),
- selected: x.version_number === version_number
+ selected: x.version_number === version_number,
+ onClick: () => onClickVersionHistory(x.version_number)
}));
- }, [versions, version_number]);
+ }, [versions, version_number, onClickVersionHistory]);
return useMemo(
() => ({