Skip to content

Commit 5f76e48

Browse files
committed
poc: use just flag and trunk on block, provide more complete default country selection on inspector controls
1 parent a6a7fb7 commit 5f76e48

File tree

2 files changed

+28
-3
lines changed
  • projects/packages/forms/src/blocks

2 files changed

+28
-3
lines changed

projects/packages/forms/src/blocks/field-telephone/edit.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import {
55
BlockContextProvider,
66
BlockControls,
77
} 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';
915
import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';
1016
import { __ } from '@wordpress/i18n';
1117
import { globe } from '@wordpress/icons';
@@ -54,6 +60,13 @@ export default function PhoneFieldEdit( props ) {
5460
useFormWrapper( props );
5561

5662
const countryPairs = useMemo( () => {
63+
return countries.map( country => ( {
64+
label: country.label,
65+
value: country.code,
66+
} ) );
67+
}, [] );
68+
69+
const countryPairsWithNames = useMemo( () => {
5770
return countries.map( country => ( {
5871
label: country.country + ' ' + country.label,
5972
value: country.code,
@@ -99,7 +112,8 @@ export default function PhoneFieldEdit( props ) {
99112
// Handler is provided as context from edit as index.js can't pass it as a prop.
100113
const onChangeDefaultCountry = useCallback(
101114
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;
103117
setAttributes( { default: value } );
104118
},
105119
[ setAttributes ]
@@ -135,6 +149,17 @@ export default function PhoneFieldEdit( props ) {
135149
onChange={ onChangeShowCountrySelector }
136150
__nextHasNoMarginBottom={ true }
137151
/>
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+
) }
138163
</PanelBody>
139164
</InspectorControls>
140165

projects/packages/forms/src/blocks/input-phone/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const PhoneInputEdit = ( { attributes, clientId, isSelected, name, setAttributes
6060
<div className="jetpack-field__input-prefix">
6161
<select
6262
className="jetpack-field__input-element"
63-
defaultValue={ defaultPrefix }
63+
value={ defaultPrefix }
6464
onChange={ onChangeDefaultPrefix }
6565
>
6666
{ prefixOptions.map( ( { label, value } ) => (

0 commit comments

Comments
 (0)