1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

Fix network dropdown button (#10312)

This fixes a bug where the network menu would remain present after a
second click on the network menu button. The bug was caused by the
click being handled _twice_, by two separate handlers. First it was
caught by the external click handler of the dropdown menu, which closed
the menu. Second, it was caught by the network button itself, which re-
opened the menu. This all happens quickly enough that to the user it
appears to stay open.

The external click handler of the menu now only fires if the menu is
open. Additionally, any click that is caught by the network menu is
stopped from propagating further, so that it can't trigger additional
click handlers.
This commit is contained in:
Mark Stacey 2021-01-30 12:12:55 -03:30 committed by GitHub
parent 6f46253e62
commit f381f41cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -1798,6 +1798,11 @@ describe('MetaMask', function () {
By.xpath(`//span[contains(text(), 'http://127.0.0.1:8545/')]`), By.xpath(`//span[contains(text(), 'http://127.0.0.1:8545/')]`),
) )
// click Mainnet to dismiss network dropdown
await driver.clickElement(
By.xpath(`//span[contains(text(), 'Ethereum Mainnet')]`),
)
assert.equal(customRpcs.length, 2) assert.equal(customRpcs.length, 2)
}) })

View File

@ -255,6 +255,7 @@ class NetworkDropdown extends Component {
) )
if (notToggleElementIndex === -1) { if (notToggleElementIndex === -1) {
event.stopPropagation()
this.props.hideNetworkDropdown() this.props.hideNetworkDropdown()
} }
}} }}

View File

@ -37,6 +37,7 @@ export default class MenuDroppoComponent extends Component {
const container = findDOMNode(this) const container = findDOMNode(this)
if ( if (
this.props.isOpen &&
target !== container && target !== container &&
!isDescendant(this.container, event.target) && !isDescendant(this.container, event.target) &&
this.props.onClickOutside this.props.onClickOutside