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

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

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

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

Loading…
Cancel
Save