Skip to content

Commit

Permalink
fix(Forms): ensure Field.SelectCountry has a fallback locale (nb-NO) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored Oct 11, 2024
1 parent cd54ed0 commit 568229a
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback, useContext, useMemo, useRef } from 'react'
import classnames from 'classnames'
import SharedContext from '../../../../shared/Context'
import { LOCALE } from '../../../../shared/defaults'
import { Autocomplete, HelpButton } from '../../../../components'
import { pickSpacingProps } from '../../../../components/flex/utils'
import countries, {
Expand Down Expand Up @@ -51,7 +52,9 @@ export type Props = FieldHelpProps &
function SelectCountry(props: Props) {
const sharedContext = useContext(SharedContext)
const translations = useTranslation().SelectCountry
const lang = sharedContext.locale?.split('-')[0] as CountryLang
const lang = (sharedContext.locale || LOCALE).split(
'-'
)[0] as CountryLang

const getCountryObjectByIso = useCallback(
(value: CountryType['iso']) => {
Expand Down Expand Up @@ -291,7 +294,7 @@ export function getCountryData({
}
}

return a[lang].localeCompare(b[lang])
return String(a[lang])?.localeCompare?.(b[lang])
})
.map((country) => makeObject(country, lang))
}
Expand Down

0 comments on commit 568229a

Please sign in to comment.