Autoscroll to active tab on load

pull/894/merge
Lim Chee Aun 2025-06-12 21:00:46 +08:00
rodzic 1de58999de
commit 96c02ce2e4
2 zmienionych plików z 26 dodań i 3 usunięć

Wyświetl plik

@ -3,7 +3,7 @@ import './shortcuts.css';
import { Trans, useLingui } from '@lingui/react/macro';
import { MenuDivider } from '@szhsin/react-menu';
import { memo } from 'preact/compat';
import { useRef, useState } from 'preact/hooks';
import { useEffect, useRef, useState } from 'preact/hooks';
import { useHotkeys } from 'react-hotkeys-hook';
import { useNavigate } from 'react-router-dom';
import { useSnapshot } from 'valtio';
@ -35,6 +35,7 @@ function Shortcuts() {
(!settings.shortcutsViewMode && settings.shortcutsColumnsMode);
const menuRef = useRef();
const tabBarRef = useRef();
const hasLists = useRef(false);
const formattedShortcuts = shortcuts
@ -83,6 +84,27 @@ function Shortcuts() {
})
.filter(Boolean);
// Auto-scroll to active tab on first render
useEffect(() => {
if (
snapStates.settings.shortcutsViewMode === 'tab-menu-bar' &&
tabBarRef.current
) {
const timeoutId = setTimeout(() => {
const activeTab = tabBarRef.current?.querySelector('.is-active');
if (activeTab) {
activeTab.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'center',
});
}
}, 100);
return () => clearTimeout(timeoutId);
}
}, []);
const navigate = useNavigate();
useHotkeys(
['1', '2', '3', '4', '5', '6', '7', '8', '9'],
@ -113,6 +135,7 @@ function Shortcuts() {
<div id="shortcuts">
{snapStates.settings.shortcutsViewMode === 'tab-menu-bar' ? (
<nav
ref={tabBarRef}
class="tab-bar"
onContextMenu={(e) => {
e.preventDefault();

4
src/locales/en.po wygenerowano
Wyświetl plik

@ -1529,7 +1529,7 @@ msgid "Lists"
msgstr ""
#: src/components/nav-menu.jsx:440
#: src/components/shortcuts.jsx:218
#: src/components/shortcuts.jsx:241
#: src/pages/list.jsx:139
msgid "All Lists"
msgstr ""
@ -1954,7 +1954,7 @@ msgid "Media only"
msgstr ""
#: src/components/shortcuts-settings.jsx:235
#: src/components/shortcuts.jsx:195
#: src/components/shortcuts.jsx:218
msgid "Shortcuts"
msgstr ""