Skip to content

MazSelectCountry ​

MazSelectCountry is a versatile Vue component for selecting countries or languages with built-in internationalization support and customizable display options

TIP

This component can be translated globally using the MazUi plugin.

Basic usage ​

The most common use case is selecting a country. The component automatically displays country names in the user's locale with their respective flags.

Selected: FR

Language selection ​

Configure the component to display languages instead of countries by setting the appropriate displayNamesOptions.

Selected: en-US

Sizes and colors ​

Sizes

Colors

Preferred countries ​

You can prioritize certain countries to appear at the top of the list using the preferredCodes prop.

Filtering options ​

Control which countries are displayed using onlyCodes to show only specific countries, or ignoredCodes to exclude certain ones.

Only European countries

Exclude specific countries

Custom display options ​

Configure how country/language names are displayed using the displayNamesOptions prop, which leverages the browser's Intl.DisplayNames API.

Short country names

Languages with narrow style

Without flags ​

Hide country flags using the hideFlags prop for a cleaner text-only interface.

Custom locale ​

Override the default locale to display country/language names in a specific language.

Countries in French

Countries in Spanish

States and validation ​

The component supports all the standard form states for better user experience.

Custom options ​

Provide your own list of options instead of using the built-in country/language codes.

Display code instead of name ​

Show country/language codes in the input field instead of names using the displayCode prop.

Advanced configuration ​

Combine multiple features for complex use cases, such as business applications requiring specific country lists with custom styling.

How it works ​

The MazSelectCountry component is built on top of MazSelect and leverages the powerful useDisplayNames composable, which uses the browser's native Intl.DisplayNames API for internationalization.

Key features: ​

  • Automatic localization: Country and language names are displayed in the user's locale
  • Built-in search: Users can quickly find countries by typing
  • Flag integration: Automatic flag display using country codes
  • Flexible filtering: Support for preferred, ignored, or specific country lists
  • Custom options: Override default behavior with custom data
  • Accessibility: Full keyboard navigation and screen reader support

useDisplayNames composable ​

The component uses the useDisplayNames composable internally, which provides:

typescript
// Get display name for a single code
const displayName = getDisplayName('FR', {
  locale: 'en-US',
  type: 'region'
})

// Get all display names with filtering
const allCountries = getAllDisplayNames({
  locale: 'en-US',
  codesType: 'country',
  preferred: ['US', 'GB', 'FR'],
  exclude: ['AQ']
})

This ensures consistent internationalization across your application while providing maximum flexibility for different use cases.

Props ​

NameDescriptionTypeRequiredDefaultPossible values
styleStyle attribut of the component root elementHTMLAttributes['style']Noundefined-
classClass attribut of the component root elementHTMLAttributes['class']Noundefined-
idId of the componentstringNoundefined-
colorColor of the componentMazColorNoprimary-
sizeSize of the componentMazSizeNomd-
preferred-codesPreferred countries to displayOption['code'][]Noundefined-
ignored-codesIgnored countries to displayOption['code'][]Noundefined-
only-codesOnly countries to displayOption['code'][]Noundefined-
list-positionPosition of the listMazPopoverProps['position']Noauto-
hide-flagsHide flagsbooleanNoundefined-
searchDisplay search input in options listbooleanNotrue-
show-code-in-listShow code on listbooleanNofalse-
localeLocalestringNolocale defined within the maz-ui plugin or browser locale or en-US-
successSuccess statebooleanNoundefined-
errorError statebooleanNoundefined-
warningWarning statebooleanNoundefined-
display-codebooleanNoundefined-
search-thresholdSearch thresholdnumberNoundefined-
translationsTranslationsPartial<MazUiTranslationsNestedSchema['selectCountry']>NoMazUiTranslationsNestedSchema['selectCountry']-
hintHint message displayedstringNoundefined-
optionsOptionsOption[]Noundefined-
display-names-optionsDisplay name typeIntl.DisplayNamesOptionsNo{ type: 'region', languageDisplay: 'standard', fallback: 'code', style: 'long' }-
codes-typeCodes typeCodesTypeNodefined by displayNamesOptions.type (if 'region', 'country' is used, otherwise 'iso')iso' | 'bcp' | 'country' | 'all
openOpen the selectbooleanNofalse-

Events ​

Event namePropertiesDescription
update:model-valuevalue Option['code'] | undefined - The new valueEmitted when the model value changes

Slots ​

NameDescriptionBindings
selector-flagCountry selector flagcountry-code String - current selected country code - Ex: "FR"
no-results
country-list-flagCountry list flagoption { code: string; name: string; } - country data
is-selected Boolean - true if option is selected
country-list-code
country-list-name