Country

import Country from 'frui/fields/Country';
Copy

Props

The following props are accepted by Country.

NameTypeRequiredNotes
classNamestringNoStandard HTML class names
defaultValuestringNoAlias to value
errorstring|booleanNoAny error message
namestringNoUsed for react server components.
onDropdownFunctionNoEvent handler when dropdown opens/closes
onSelectedFunctionNoEvent handler when an option has been selected
onUpdateFunctionNoUpdate event handler
optionsstring[]NoList of select options.
placeholderstringNoDisplay text when no value set
searchablebooleanNoAdd a search field
styleCSS ObjectNoStandard CSS object
valuestringNoSelected value from the options

Basics

The following is a basic example of an Country field.

Select Country
<Country className="w-full z-30 text-black" placeholder="Select Country" searchable />
Copy

Events

The following example makes use of all the possible events for Country.

Choose a Country
<Country 
  className="w-full z-20 text-black" 
  onDropdown={open => console.log('dropdown', open)}
  onSelected={option => console.log('selected', option)}
  onUpdate={value => alert(JSON.stringify(value))}
/>
Copy

On Dropdown

The onDropdown event is triggered when the dropdown opens or closes. The following arguments are passed to the event handler:

NameTypeSample
openbooleantrue

On Selected

The onSelected event is triggered when an option has been selected. The following arguments are passed to the event handler:

NameTypeSample
optionSelectOption
{
  label: 'United States',
  value: {
    countryCode: 'US',
    countryName: 'United States',
    currencyType: 'fiat',
    currencyCode: 'USD',
    currencyName: 'US Dollar',
    currencyPlural: 'US Dollars',
    currencySymbol: '$',
    language: 'en'
  }
}

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valueCountryData
{
  countryCode: 'US',
  countryName: 'United States',
  currencyType: 'fiat',
  currencyCode: 'USD',
  currencyName: 'US Dollar',
  currencyPlural: 'US Dollars',
  currencySymbol: '$',
  language: 'en'
}

Errors

You can pass the error prop to highlight the Country field red.

Choose a Country
<Country className="w-full z-10 text-black" error={string|true} value="US" />
Copy

Custom Styles

You can add your own custom class to selects or use any of the respective frui-field-select, frui-field-select-control, frui-field-select-placeholder, frui-field-select-dropdown, frui-field-select-search, frui-field-select-search-control, frui-field-select-search-icon, frui-field-select-options, frui-field-select-option, and frui-field-select-label CSS classes.