From 6760ae0e84b614b496bf73fab30970ee824f49d6 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 3 Mar 2017 14:38:40 +0100 Subject: [PATCH] Account selector close operations (#4728) * Close when clicking anywhere on body pane * Allow click to propagate on address click * Rename noCopy -> allowAddressClick * Handle i18n strings in input * Close on pasted addresses (valid entry) * allowAddressClick default * Don't do onClick on AccountCard if text is selected * Reset filter value on close for address selection * Better close on click for AccountSelection --- js/src/ui/AccountCard/accountCard.js | 31 ++++++++++++++++--- js/src/ui/Form/AddressSelect/addressSelect.js | 13 ++++++++ .../InputAddressSelect/inputAddressSelect.js | 8 +++-- js/src/ui/Portal/portal.js | 13 +++++++- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/js/src/ui/AccountCard/accountCard.js b/js/src/ui/AccountCard/accountCard.js index 6a6ebb22c..d7b455132 100644 --- a/js/src/ui/AccountCard/accountCard.js +++ b/js/src/ui/AccountCard/accountCard.js @@ -28,12 +28,17 @@ import styles from './accountCard.css'; export default class AccountCard extends Component { static propTypes = { account: PropTypes.object.isRequired, + allowAddressClick: PropTypes.bool, balance: PropTypes.object, className: PropTypes.string, onClick: PropTypes.func, onFocus: PropTypes.func }; + static defaultProps = { + allowAddressClick: false + }; + state = { copied: false }; @@ -122,7 +127,7 @@ export default class AccountCard extends Component {
@@ -132,6 +137,17 @@ export default class AccountCard extends Component { ); } + handleAddressClick = (event) => { + const { allowAddressClick } = this.props; + + // Don't stop the event if address click is allowed + if (allowAddressClick) { + return this.onClick(event); + } + + return this.preventEvent(event); + } + handleKeyDown = (event) => { const codeName = keycode(event); @@ -172,9 +188,14 @@ export default class AccountCard extends Component { } } - onClick = () => { + onClick = (event) => { const { account, onClick } = this.props; + // Stop the default event if text is selected + if (window.getSelection && window.getSelection().type === 'Range') { + return this.preventEvent(event); + } + onClick && onClick(account.address); } @@ -184,9 +205,9 @@ export default class AccountCard extends Component { onFocus && onFocus(account.index); } - preventEvent = (e) => { - e.preventDefault(); - e.stopPropagation(); + preventEvent = (event) => { + event.preventDefault(); + event.stopPropagation(); } setTagRef = (tagRef) => { diff --git a/js/src/ui/Form/AddressSelect/addressSelect.js b/js/src/ui/Form/AddressSelect/addressSelect.js index 07c133d7c..785a8fa65 100644 --- a/js/src/ui/Form/AddressSelect/addressSelect.js +++ b/js/src/ui/Form/AddressSelect/addressSelect.js @@ -23,6 +23,7 @@ import { observer } from 'mobx-react'; import TextFieldUnderline from 'material-ui/TextField/TextFieldUnderline'; +import apiutil from '~/api/util'; import AccountCard from '~/ui/AccountCard'; import InputAddress from '~/ui/Form/InputAddress'; import Loading from '~/ui/Loading'; @@ -177,6 +178,7 @@ class AddressSelect extends Component { { + event.stopPropagation(); + } + handleInputAddresKeydown = (event) => { const code = keycode(event); @@ -588,6 +596,7 @@ class AddressSelect extends Component { } this.store.resetRegistryValues(); + this.store.handleChange(''); this.setState({ expanded: false, @@ -613,6 +622,10 @@ class AddressSelect extends Component { focusedItem: null, inputValue: value }); + + if (apiutil.isAddressValid(value)) { + this.handleClick(value); + } } } diff --git a/js/src/ui/Form/InputAddressSelect/inputAddressSelect.js b/js/src/ui/Form/InputAddressSelect/inputAddressSelect.js index c6c3fe6a4..8199fece6 100644 --- a/js/src/ui/Form/InputAddressSelect/inputAddressSelect.js +++ b/js/src/ui/Form/InputAddressSelect/inputAddressSelect.js @@ -17,6 +17,8 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; +import { nodeOrStringProptype } from '~/util/proptypes'; + import AddressSelect from '../AddressSelect'; class InputAddressSelect extends Component { @@ -27,9 +29,9 @@ class InputAddressSelect extends Component { allowCopy: PropTypes.bool, className: PropTypes.string, - error: PropTypes.string, - hint: PropTypes.string, - label: PropTypes.string, + error: nodeOrStringProptype(), + hint: nodeOrStringProptype(), + label: nodeOrStringProptype(), onChange: PropTypes.func, readOnly: PropTypes.bool, value: PropTypes.string diff --git a/js/src/ui/Portal/portal.js b/js/src/ui/Portal/portal.js index 213b2f7a9..9d270b0cc 100644 --- a/js/src/ui/Portal/portal.js +++ b/js/src/ui/Portal/portal.js @@ -44,6 +44,7 @@ export default class Portal extends Component { hideClose: PropTypes.bool, isChildModal: PropTypes.bool, isSmallModal: PropTypes.bool, + onClick: PropTypes.func, onKeyDown: PropTypes.func, steps: PropTypes.array, title: nodeOrStringProptype() @@ -89,7 +90,7 @@ export default class Portal extends Component { className ].join(' ') } - onClick={ this.stopEvent } + onClick={ this.handleContainerClick } onKeyDown={ this.handleKeyDown } > { + const { onClick } = this.props; + + if (!onClick) { + return this.stopEvent(event); + } + + return onClick(event); + } + handleClose = () => { const { hideClose, onClose } = this.props;