Country selection

Learn how to customise the country selection component.

Styling

const countrySelectionConfig: CountrySelectionComponentConfig = {
  inputAttributes: InputAttributes,
  required: boolean,
  placeholder: string,
  componentStyles: {
    base: CSSProperties,
    valid: CSSProperties,
    invalid: CSSProperties,
    input: CSSProperties
  },
  inputStyles: {
    base: CSSProperties,
    valid: CSSProperties,
    invalid: CSSProperties
  },
  label: string,
  labelStyles: {
    base: CSSProperties,
    valid: CSSProperties,
    invalid: CSSProperties
  },
  labelPosition: string,
  invalidTextStyles: CSSProperties,
  invalidTextPosition: string,
  guideText: string,
  validations: {},
  invalidIconSrc: string,
  validIconSrc: string,
  displayValidIcon: boolean,
  displayInvalidIcon: boolean,
  tooltipAriaLabel: string,
  ariaLabel: string,
  displayRequiredIcon: boolean,
  allowToCopyPaste: boolean,
  validationOnBlur: boolean,
  validationOnChange: boolean,
  tabIndex: number,
  noCountryText: string,
  dropdownStyles: CSSProperties,
  dropdownOptionStyles: {
    selected: CSSProperties,
    unselected: CSSProperties,
    hover: CSSProperties,
  }
};

Property

Description

inputAttributes
InputAttributes

Additional HTML input attributes.

required
boolean

Whether the field is required for submission.

placeholder
string

The placeholder text to display when the field is empty.

componentStyles
ComponentStyles

Custom styling for the component.

componentStyles.base
CSSProperties

Base styling for the component.

componentStyles.valid
CSSProperties

Styling for the component when it's valid.

componentStyles.invalid
CSSProperties

Styling for the component when it's not valid.

componentStyles.input
CSSProperties

Styling for the input element.

inputStyles
StateStyles

Style for input field in various states.

label
string

The input label's text.

labelStyles
StateStyles

The label styling, based on the state.

labelPosition
string (enum)

The position of the label, relative to the input field.

Possible values:

  • above
  • below
  • left
  • right

invalidTextStyles
CSSProperties

Style for validation message text.

invalidTextPosition
string (enum)

The position of the invalid text message, relative to the input field.

Possible values:

  • above
  • below
  • left
  • right

guideText
string

The helper text to display below the input field.

validations
T

Validation rules to be applied to the input field.

invalidIconSrc
string

The URL for the icon shown on invalid input.

validIconSrc
string

The URL for the icon shown on valid input.

displayValidIcon
boolean

Whether to display a success icon. Defaults to true.

displayInvalidIcon
boolean

Whether to display an error icon. Defaults to true.

tooltipAriaLabel
string

The aria label for the tooltip.

ariaLabel
string

The aria label for the field component.

displayRequiredIcon
boolean

Whether to display a required icon. Defaults to true.

allowToCopyPaste
boolean

Whether to allow copy/paste in the input fields.

validationOnBlur
boolean

Whether to run validation when input loses focus.

validationOnChange
boolean

Whether to run validation as a value changes.

tabIndex
number

The tab index of the input element.

noCountryText
string

The text to display when no country is found.

dropdownStyles
CSSProperties

Custom styling for the country selection component.

dropdownOptionStyles
object

Custom styling for drop-down options in different states.

dropdownOptionStyles.selected
CSSProperties

Custom styling applied to the currently-selected option.

dropdownOptionStyles.unselected
CSSProperties

Custom styling applied to options that aren't selected.

dropdownOptionStyles.hover
CSSProperties

Custom styling applied when hovering over an option.

Example

const countrySelectionConfig: CountrySelectionComponentConfig = {
  label: "Country",
  placeholder: "Select country",
  required: true,
  noCountryText: "No country found",
  validationOnBlur: true,
  validationOnChange: true,  
  inputStyles: {
    base: {
      border: "1px solid #ccc",
      padding: "12px",
      borderRadius: "4px",
      fontSize: "16px",
      cursor: "pointer"
    },
    valid: {
      borderColor: "#28a745"
    },
    invalid: {
      borderColor: "#dc3545"
    }
  }, 
  labelStyles: {
    base: {
      fontWeight: "500",
      marginBottom: "8px"
    }
  }, 
  dropdownStyles: {
    maxHeight: "200px",
    overflowY: "auto",
    border: "1px solid #ccc",
    borderRadius: "4px",
    boxShadow: "0 2px 8px rgba(0,0,0,0.1)"
  },  
  dropdownOptionStyles: {
    selected: {
      backgroundColor: "#007bff",
      color: "#ffffff"
    },
    unselected: {
      backgroundColor: "#ffffff",
      color: "#333333",
      padding: "8px 12px"
    },
    hover: {
      backgroundColor: "#f8f9fa",
      cursor: "pointer"
    }
  },  
  tabIndex: 1, 
  onChange: (event) => {
    console.log("Country changed:", event.target.value);
  },
  onFocus: (event) => {
    console.log("Country dropdown focused");
  },
  onBlur: (event) => {
    console.log("Country dropdown blurred");
  },
  onValidationPassed: (data) => {
    console.log("Country selection valid");
  },
  onValidationFailed: (data) => {
    console.log("Country selection validation failed:", data);
  }
};