Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scroll to the active account #131

Merged
merged 1 commit into from
Feb 7, 2025
Merged
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
feat: scroll to the active account
vvava committed Jan 31, 2025
commit 8c2677d1743b132e0507da44b04259f4b004a217
13 changes: 13 additions & 0 deletions src/pages/Accounts/components/AccountItem.tsx
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import {
ForwardedRef,
forwardRef,
useCallback,
useEffect,
useMemo,
useRef,
useState,
@@ -79,6 +80,18 @@ export const AccountItem = forwardRef(
const address = network ? getAddressForChain(network.chainId, account) : '';
const [cardHovered, setCardHovered] = useState(false);
const itemRef = useRef<HTMLDivElement>(null);
const firstPageload = useRef(true);

useEffect(() => {
if (isActive) {
const behavior = firstPageload.current ? 'instant' : 'smooth';
itemRef?.current?.scrollIntoView({
block: 'center',
behavior,
});
}
firstPageload.current = false;
}, [isActive]);

const toggle = useCallback(
(accountId: string) => {