Skip to main content

CountrySelect

The CountrySelect component is a form component that enables a user to select a single option from a dropdown menu as well as behaving like a standard text input with autocomplete options.

Types

The CountrySelect component supports two types:

  • country (default): Displays country names for selection
  • phone: Displays country phone codes (e.g., +1, +44, +49) for phone number input scenarios

Import

// with @dhl-official/react-library:
import { DhlCountrySelect } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlCountrySelect } from "@dhl-official/ui-libraries/react-library"

Code

<DhlCountrySelect
variant={{
label: "Select Country",
placeholder: "Select Country",
}}
/>

Examples

Example 1

Country Type (Default)


Code example
<DhlCountrySelect
variant={{
label: "Select Country",
placeholder: "Select Country",
}}
/>

Example 2

Phone Code Type


Code example
<DhlCountrySelect
type={DHL_COUNTRY_SELECT.TYPE.PHONE}
variant={{
label: "Select Country",
placeholder: "Select Country",
}}
/>

Example 3

With specific countries only


Code example
import { DhlCountrySelect } from "@dhl-official/react-library";
import { DHL_COUNTRY_SELECT } from "@dhl-official/stencil-library";

<DhlCountrySelect
variant={{
label: "Select Country",
placeholder: "Select Country",
}}
filteredList={[
DHL_COUNTRY_SELECT.COUNTRY_CODES.au,
DHL_COUNTRY_SELECT.COUNTRY_CODES.be,
DHL_COUNTRY_SELECT.COUNTRY_CODES.dk,
DHL_COUNTRY_SELECT.COUNTRY_CODES.cz,
DHL_COUNTRY_SELECT.COUNTRY_CODES.de,
DHL_COUNTRY_SELECT.COUNTRY_CODES.es,
DHL_COUNTRY_SELECT.COUNTRY_CODES.it,
DHL_COUNTRY_SELECT.COUNTRY_CODES.hr,
DHL_COUNTRY_SELECT.COUNTRY_CODES.se,
DHL_COUNTRY_SELECT.COUNTRY_CODES.fr,
DHL_COUNTRY_SELECT.COUNTRY_CODES.fi,
DHL_COUNTRY_SELECT.COUNTRY_CODES.pl,
DHL_COUNTRY_SELECT.COUNTRY_CODES.nl,
DHL_COUNTRY_SELECT.COUNTRY_CODES.pt
]}
/>

Interactive Demo

Readme

Properties

PropertyAttributeDescriptionTypeDefault
changeEventchange-event[DEPRECATED] Use dhlChange event instead

An optional input onChange callback handler.
(value: string) => booleanundefined
customFiltercustom-filterAn optional callback handler that accepts the options and input data, used for custom filtering. If this function is not passed, by default, filtering will happen on the "label" key of the item if its an object or the actual value if the item is a primitive data type(options: unknown, value: string) => DhlSelectionOptionType[]undefined
dataAriaDescribedbydata-aria-describedbyAn optional prop defining the list of reference IDs (separated by spaces), recommended when you want to an error message on your field.stringundefined
dataAriaExpandeddata-aria-expandedAn optional prop used for assistive technology support - used to mark expandable and collapsible regions.stringundefined
dataIddata-idAn optional prop. Gives a valid HTML ID attribute value for the component.stringundefined
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
filteredListfiltered-listAn optional prop to specify array of country codes in order to have filtered list of countries. Country codes array examples: ["ar", "cz", "de", "es", "it", "au"] or [ DHL_COUNTRY_SELECT.COUNTRY_CODES.ar, DHL_COUNTRY_SELECT.COUNTRY_CODES.au, DHL_COUNTRY_SELECT.COUNTRY_CODES.es]string[][]
getItemLabelget-item-labelAn optional prop used to read the label of an option.(option: any) => voidundefined
isDisabledis-disabledAn optional flag to define if the component is disabled.booleanfalse
localelocaleAn optional prop flag to define locale for country names. In case when unsupported locale will be passed, then country names will fallback to default names in English.stringundefined
namenameAn optional value to be set to the element HTML name attribute. It takes any valid value that can be used for the name attribute of an HTMLInputElement.stringundefined
openOnFocusopen-on-focusAn optional prop when set to true, the select option list will be shown on input focus.booleanfalse
optionClickEventoption-click-event[DEPRECATED] Use dhlClickOption event instead

An optional callback for option click event, option is passed as callback parameter.
(option: DhlSelectionOptionType) => voidundefined
readonlyreadonlyAn optional flag to define if the component is readonly.booleanfalse
requiredrequiredAn optional prop to flag the component as required within a form context.booleanundefined
showAllOptionsAfterSelectionshow-all-options-after-selectionAn optional prop flag to define if options should be filtered after selection.booleantrue
showClearButtonshow-clear-buttonAn optional prop flag to define if clear button is displayed.booleanfalse
showPlaceholderImageshow-placeholder-imageAn optional prop to define placeholder image.booleanfalse
showRightIconshow-right-iconAn optional prop flag to define if right icon is displayed.booleantrue
showSmallImageshow-small-imageAn optional prop flag to define if small image is displayed.booleantrue
sizesizeAn optional prop to define the size of the component.Sizes.MD | Sizes.SMSizes.MD
typetypeAn optional prop to define the type of the component."country" | "phone"DHL_COUNTRY_SELECT.TYPE.COUNTRY
validationvalidationAn optional object to set-up a custom components validation state. Required Fields: type{ type: Variants.warning | Variants.valid | Variants.invalid | Variants.note; message?: string; }undefined
valuevalueAn optional prop defining the value of the component which is taken when a form is submitted.string""
variantvariantA REQUIRED object to set-up a custom components variant state. It can be used to set a custom label and a custom placeholder text. label is required. placeholder is optional. type property was removed because animated behavior of label and placeholder is no longer supported. When placeholder is not provided, then label stays permanently animated.{ label: string; placeholder?: string; }{ label: "Select Country", placeholder: "Select Country", }

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!