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 |
---|---|
| Additional HTML input attributes. |
| Whether the field is required for submission. |
| The placeholder text to display when the field is empty. |
| Custom styling for the component. |
| Base styling for the component. |
| Styling for the component when it's valid. |
| Styling for the component when it's not valid. |
| Styling for the input element. |
| Style for input field in various states. |
| The input label's text. |
| The label styling, based on the state. |
| The position of the label, relative to the input field.
|
| Style for validation message text. |
| The position of the invalid text message, relative to the input field.
|
| The helper text to display below the input field. |
| Validation rules to be applied to the input field. |
| The URL for the icon shown on invalid input. |
| The URL for the icon shown on valid input. |
| Whether to display a success icon. Defaults to |
| Whether to display an error icon. Defaults to |
| The aria label for the tooltip. |
| The aria label for the field component. |
| Whether to display a required icon. Defaults to |
| Whether to allow copy/paste in the input fields. |
| Whether to run validation when input loses focus. |
| Whether to run validation as a value changes. |
| The tab index of the input element. |
| The text to display when no country is found. |
| Custom styling for the country selection component. |
| Custom styling for drop-down options in different states. |
| Custom styling applied to the currently-selected option. |
| Custom styling applied to options that aren't selected. |
| 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);
}
};
Updated 3 days ago