fix(#170): open countries popup on input focus (#18)

keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 6 years ago committed by GitHub
parent 5f152d7b40
commit 332249e29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/features/Combobox/index.tsx
  2. 1
      src/features/Combobox/types.tsx
  3. 12
      src/features/Register/components/RegistrationStep/hooks/useCountries.tsx
  4. 1
      src/features/Register/components/RegistrationStep/index.tsx

@ -23,6 +23,7 @@ export const Combobox = <T extends Option>(props: Props<T>) => {
id,
label,
labelWidth,
openOnFocus,
pattern,
required,
} = props
@ -37,7 +38,7 @@ export const Combobox = <T extends Option>(props: Props<T>) => {
} = useCombobox(props)
return (
<ComboboxStyled onSelect={onOptionSelect}>
<ComboboxStyled openOnFocus={openOnFocus} onSelect={onOptionSelect}>
<Label
labelWidth={labelWidth}
htmlFor={id}

@ -16,6 +16,7 @@ export type Props<T> = Pick<InputHTMLAttributes<HTMLInputElement>, (
labelWidth?: number,
onChange?: (event: ChangeEvent<HTMLInputElement>) => void,
onSelect?: (option: T | null) => void,
openOnFocus?: boolean,
options: Array<T>,
value?: string,
}

@ -4,6 +4,7 @@ import {
useMemo,
} from 'react'
import orderBy from 'lodash/orderBy'
import map from 'lodash/map'
import type { Countries } from 'requests'
@ -33,10 +34,13 @@ export const useCountries = () => {
const nameField = `name_${lang}` as 'name_eng'
const transformedCountries = useMemo(
() => map(countries, (country) => ({
id: country.id,
name: country[nameField],
})),
() => orderBy(
map(countries, (country) => ({
id: country.id,
name: country[nameField],
})),
'name',
),
[countries, nameField],
)

@ -75,6 +75,7 @@ export const RegistrationStep = () => {
/>
<Combobox
required
openOnFocus
id={formIds.country}
label='Страна'
labelWidth={labelWidth}

Loading…
Cancel
Save