1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 03:12:42 +02:00

UX: Ensure currently selected account displays when Account Menu opens (#20166)

* UX: Ensure currently selected account displays when Account Menu opens

* Jest tests
This commit is contained in:
David Walsh 2023-07-26 14:38:19 -05:00 committed by Dan J Miller
parent 41bab4a6e1
commit 5db22ceb84

View File

@ -1,4 +1,4 @@
import React, { useState, useContext } from 'react';
import React, { useState, useContext, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
@ -87,6 +87,15 @@ export const AccountListItem = ({
setAccountListItemMenuElement(ref);
};
// If this is the selected item in the Account menu,
// scroll the item into view
const itemRef = useRef(null);
useEffect(() => {
if (selected) {
itemRef.current?.scrollIntoView?.();
}
}, [itemRef, selected]);
const keyring = useSelector((state) =>
findKeyringForAddress(state, identity.address),
);
@ -103,6 +112,7 @@ export const AccountListItem = ({
'multichain-account-list-item--selected': selected,
'multichain-account-list-item--connected': Boolean(connectedAvatar),
})}
ref={itemRef}
onClick={() => {
// Without this check, the account will be selected after
// the account options menu closes