@@ -5,7 +5,13 @@ import {
5
5
BlockContextProvider ,
6
6
BlockControls ,
7
7
} from '@wordpress/block-editor' ;
8
- import { PanelBody , ToggleControl , ToolbarButton , ToolbarGroup } from '@wordpress/components' ;
8
+ import {
9
+ PanelBody ,
10
+ ToggleControl ,
11
+ ToolbarButton ,
12
+ ToolbarGroup ,
13
+ SelectControl ,
14
+ } from '@wordpress/components' ;
9
15
import { useCallback , useEffect , useMemo , useState } from '@wordpress/element' ;
10
16
import { __ } from '@wordpress/i18n' ;
11
17
import { globe } from '@wordpress/icons' ;
@@ -54,6 +60,13 @@ export default function PhoneFieldEdit( props ) {
54
60
useFormWrapper ( props ) ;
55
61
56
62
const countryPairs = useMemo ( ( ) => {
63
+ return countries . map ( country => ( {
64
+ label : country . label ,
65
+ value : country . code ,
66
+ } ) ) ;
67
+ } , [ ] ) ;
68
+
69
+ const countryPairsWithNames = useMemo ( ( ) => {
57
70
return countries . map ( country => ( {
58
71
label : country . country + ' ' + country . label ,
59
72
value : country . code ,
@@ -99,7 +112,8 @@ export default function PhoneFieldEdit( props ) {
99
112
// Handler is provided as context from edit as index.js can't pass it as a prop.
100
113
const onChangeDefaultCountry = useCallback (
101
114
event => {
102
- const value = event . target . value ;
115
+ // if event is an array, we're using the select control
116
+ const value = Array . isArray ( event ) ? event [ 0 ] : event . target . value ;
103
117
setAttributes ( { default : value } ) ;
104
118
} ,
105
119
[ setAttributes ]
@@ -135,6 +149,17 @@ export default function PhoneFieldEdit( props ) {
135
149
onChange = { onChangeShowCountrySelector }
136
150
__nextHasNoMarginBottom = { true }
137
151
/>
152
+ { showCountrySelector && (
153
+ < SelectControl
154
+ __next40pxDefaultSize
155
+ __nextHasNoMarginBottom
156
+ label = { __ ( 'Default country' , 'jetpack-forms' ) }
157
+ multiple
158
+ onChange = { onChangeDefaultCountry }
159
+ options = { countryPairsWithNames }
160
+ value = { [ defaultCountry ] }
161
+ />
162
+ ) }
138
163
</ PanelBody >
139
164
</ InspectorControls >
140
165
0 commit comments