Country Select Component
A searchable country picker with flag emojis, built on the select component.
Preview
<%= basecoat_country_select_tag :country,
countries: %w[US CA GB DE FR NL BE ES IT PT JP BR AU SE NO],
priority: %w[US CA GB],
selected: "NL" %>
Usage
<%# Basic usage (all countries): %>
<%= basecoat_country_select_tag :country %>
<%# With pre-selected country: %>
<%= basecoat_country_select_tag :country, selected: "US" %>
<%# With priority countries at the top: %>
<%= basecoat_country_select_tag :country, priority: ["US", "CA", "GB"] %>
<%# Only show specific countries: %>
<%= basecoat_country_select_tag :country, countries: ["US", "CA", "MX"] %>
<%# Exclude specific countries: %>
<%= basecoat_country_select_tag :country, except: ["KP", "IR"] %>
<%# In a form: %>
<%= form_for @user do |f| %>
<%= f.basecoat_country_select :country %>
<% end %>
Options
| Option | Description |
|---|---|
selected | Pre-select a country by ISO 3166-1 alpha-2 code (e.g. "US") |
priority | Country codes shown at the top of the list |
countries | Only include these country codes |
except | Exclude these country codes |
| Plus all select component options (placeholder, scrollable, ...) | |
Requires the countries gem
gem "countries" to your Gemfile. Country names and flags come from ISO 3166 data.