Raw
1 ---
2 sidebar_label: "Country Select"
3 ---
4
5 import { TypeList } from "docs-ui"
6
7 export const metadata = {
8 title: `CountrySelect - Admin Components`,
9 }
10
11 # {metadata.title}
12
13 <Note>
14
15 This component is available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0).
16
17 </Note>
18
19 The `CountrySelect` component is a [Combobox](../combobox/page.mdx) pre-populated with countries, where the value of a country is its lowercased ISO 2 code. The Medusa Admin uses it in address and shipping forms.
20
21 ```tsx
22 import { CountrySelect } from "@medusajs/dashboard/components"
23 ```
24
25 ---
26
27 ## Example
28
29 Use `CountrySelect` as the control of a `Form` field, as shown in the [Forms guide](../../guides/forms/page.mdx):
30
31 ```tsx
32 import {
33 CountrySelect,
34 Form,
35 } from "@medusajs/dashboard/components"
36
37 const CountryField = ({ control }) => {
38 return (
39 <Form.Field
40 control={control}
41 name="country_code"
42 render={({ field }) => (
43 <Form.Item>
44 <Form.Label>Country</Form.Label>
45 <Form.Control>
46 <CountrySelect
47 autoComplete="country_code"
48 {...field}
49 />
50 </Form.Control>
51 <Form.ErrorMessage />
52 </Form.Item>
53 )}
54 />
55 )
56 }
57 ```
58
59 The field's value is the country's ISO 2 code in lowercase, such as `us`, which is the format that the Medusa backend expects.
60
61 ---
62
63 ## Props
64
65 `CountrySelect` accepts the same props as [Combobox](../combobox/page.mdx), except for `options`, since it populates the countries itself. It also accepts the following props:
66
67 <TypeList
68 types={[
69 {
70 name: "value",
71 type: "`string`",
72 optional: true,
73 description: `The selected country's ISO 2 code in lowercase.`,
74 },
75 {
76 name: "onChange",
77 type: "`(value: string | undefined) => void`",
78 optional: true,
79 description: `The function to execute when the user selects a country. It receives the country's ISO 2 code in lowercase.`,
80 },
81 {
82 name: "defaultValue",
83 type: "`string`",
84 optional: true,
85 description: `The ISO 2 code of the country to select by default.`,
86 },
87 {
88 name: "placeholder",
89 type: "`string`",
90 optional: true,
91 description: `The placeholder to show when the user hasn't selected a country. Defaults to a localized "Select country" text.`,
92 },
93 {
94 name: "allowClear",
95 type: "`boolean`",
96 optional: true,
97 description: `Whether to show a button that clears the selected country.`,
98 },
99 ]}
100 />