Browse Source

Merge pull request #1736 from valpinkman/fix/autofocus-add-account

LL-659 fix autofocus on add account modal
gre-patch-1
Gaëtan Renaudeau 6 years ago
committed by GitHub
parent
commit
ed04304e82
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/components/SelectCurrency/index.js
  2. 18
      src/components/base/Select/index.js

12
src/components/SelectCurrency/index.js

@ -18,6 +18,7 @@ type OwnProps = {
currencies?: CryptoCurrency[],
value?: CryptoCurrency,
placeholder: string,
autoFocus?: boolean,
t: T,
}
@ -29,12 +30,21 @@ const mapStateToProps = (state, props: OwnProps) => ({
currencies: props.currencies || availableCurrencies(state),
})
const SelectCurrency = ({ onChange, value, t, placeholder, currencies, ...props }: Props) => {
const SelectCurrency = ({
onChange,
value,
t,
placeholder,
currencies,
autoFocus,
...props
}: Props) => {
const options = currencies
? currencies.map(c => ({ ...c, value: c.id, label: c.name, currency: c }))
: []
return (
<Select
autoFocus={autoFocus}
value={value}
renderOption={renderOption}
renderValue={renderOption}

18
src/components/base/Select/index.js

@ -28,6 +28,7 @@ type Props = {
small: boolean,
width: number,
minWidth: number,
autoFocus: boolean,
}
export type Option = {
@ -37,6 +38,19 @@ export type Option = {
}
class Select extends PureComponent<Props> {
componentDidMount() {
if (this.ref && this.props.autoFocus) {
// $FlowFixMe
this.timeout = requestAnimationFrame(() => this.ref.focus())
}
}
componentWillUnmount() {
if (this.timeout) {
cancelAnimationFrame(this.timeout)
}
}
handleChange = (value, { action }) => {
const { onChange } = this.props
if (action === 'select-option') {
@ -47,6 +61,9 @@ class Select extends PureComponent<Props> {
}
}
ref: *
timeout: *
render() {
const {
value,
@ -68,6 +85,7 @@ class Select extends PureComponent<Props> {
return (
<ReactSelect
ref={c => (this.ref = c)}
value={value}
maxMenuHeight={300}
classNamePrefix="select"

Loading…
Cancel
Save