Skip to content

Conversation

CGastrell
Copy link
Contributor

@CGastrell CGastrell commented Aug 29, 2025

Phone field with country selector, second iteration.

Proposed changes:

This PR implements a searchable dropdown for the country selector on the phone field.

  • opens and scrolls to selected
  • search as you type
  • hitting "Enter" selects the first country on the filtered list
  • changes when international phone number is typed on sibling input

Working on the editor:

Screen.Recording.2025-09-05.at.16.14.53.mov

Working on the frontend:

Screen.Recording.2025-09-05.at.16.16.01.mov

NOTE: the default country setting on the inspector sidebar can remain as a secondary way of setting it or we can remove it all along. It doesn't look as nice, but as a setting it also makes sense to leave it there.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

None

Does this pull request change what data or activity we track or use?

No

Testing instructions:

Test:

  • phone number validation, use different countries and inputs
  • special note on the editor: the labels have been rolled back to just flag and prefix (trunk) while adding a more readable default country selection on the inspector sidebar
  • test dropdown search and navigation, double check phone number validation still makes sense after changing

@CGastrell CGastrell self-assigned this Aug 29, 2025
@CGastrell CGastrell added [Status] In Progress [Type] Task [Package] Forms Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR labels Aug 29, 2025
Copy link
Contributor

github-actions bot commented Aug 29, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/forms-fancy-country-dropdown branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-fancy-country-dropdown

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link

jp-launch-control bot commented Aug 29, 2025

Code Coverage Summary

Coverage changed in 6 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/modules/field-phone/view.js 0/115 (0.00%) 0.00% 68 💔
projects/packages/forms/src/blocks/input-phone/edit.js 0/29 (0.00%) 0.00% 13 💔
projects/packages/forms/src/blocks/field-telephone/edit.js 0/25 (0.00%) 0.00% 3 ❤️‍🩹
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 412/1293 (31.86%) -0.05% 2 ❤️‍🩹
projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php 385/590 (65.25%) 0.06% 0 💚

2 files are newly checked for coverage.

File Coverage
projects/packages/forms/src/blocks/field-telephone/country-names-translated.js 0/3 (0.00%) 💔
projects/packages/forms/src/blocks/shared/components/searchable-combobox.js 0/106 (0.00%) 💔

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@CGastrell CGastrell force-pushed the add/forms-fancy-country-dropdown branch 4 times, most recently from 5f76e48 to d99c473 Compare September 2, 2025 14:34
@@ -314,7 +314,7 @@
word-break: normal;
color: unset;
opacity: 0.6;
font-size: 85%;
font-size: 72%;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically because we have a lot of broken stuff when it comes to new selectors and animated and outlined styles. This is just a wee fix for the font size given to notched labels on those form styles.

I'll be adding more like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get generic fixes merged in separate PRs to isolate them for easier testing.

Copy link
Member

@enejb enejb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some questions and suggestion! Thanks for working in this!

/**
* Test for telephone field_renders with showcountryselector false
*/
public function test_make_sure_telephone_field_renders_as_expected_with_showcountryselector() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

display: flex;
max-width: 40%;
// display: flex;
// width: 40%;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just remove this comment?

data-wp-on--keydown="actions.phoneComboboxKeydownHandler">
<div class="jetpack-combobox-options">
<template
data-wp-each--filtered="context.filteredCountries"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: indentation seems off.

import parsePhoneNumber, { AsYouType } from 'libphonenumber-js';
import { countries } from '../../blocks/field-phone/country-list';
import { countries } from '../../blocks/field-telephone/country-list';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this list is currently not translated. Should we wait till that is the case before adding it to production?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the translation comes from an internal method on the field class. This was so the translations can be provided as interactivity config:

		$translated_countries = $this->get_translatable_countries();
		$global_config        = array(
			'i18n' => array(
				'countryNames' => $translated_countries,
			),
		);
		wp_interactivity_config( 'jetpack/field-phone', $global_config );

@CGastrell CGastrell force-pushed the add/forms-fancy-country-dropdown branch from 58eab79 to 8407703 Compare September 2, 2025 21:34
@CGastrell CGastrell requested a review from enejb September 2, 2025 21:34
'jetpack-field',
'jetpack-field-phone',
'jetpack-field-telephone',
width ? ` jetpack-field__width-${ width }` : '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without space, since clx takes care of it?

Suggested change
width ? ` jetpack-field__width-${ width }` : '',
width ? `jetpack-field__width-${ width }` : '',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I guess this would work too?

Suggested change
width ? ` jetpack-field__width-${ width }` : '',
{ `jetpack-field__width-${ width }`: width },

@@ -1,13 +1,16 @@
.jetpack-contact-form .jetpack-field.jetpack-field-phone {
.jetpack-contact-form .jetpack-field.jetpack-field-phone,
.jetpack-contact-form .jetpack-field.jetpack-field-telephone {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both classes probably not needed anymore?

@@ -7,8 +7,11 @@ import save from './save';
const name = 'phone-input';
const settings = {
apiVersion: 3,
title: __( 'International Phone Input', 'jetpack-forms' ),
description: __( 'A compound input for international phone numbers.', 'jetpack-forms' ),
title: __( 'Phone Input', 'jetpack-forms' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: __( 'Phone Input', 'jetpack-forms' ),
title: __( 'Phone input', 'jetpack-forms' ),

Sentence case everywhere :-)

description: __( 'A compound input for international phone numbers.', 'jetpack-forms' ),
title: __( 'Phone Input', 'jetpack-forms' ),
description: __(
'A compound input for phone numbers with international support.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'A compound input for phone numbers with international support.',
'Phone number input.',

We could keep it simple?

@simison
Copy link
Member

simison commented Sep 3, 2025

Getting there!

I don't think we need this sidebar setting since the dropdown in canvas already works well for setting the default:

image

Carret needs better centering, and let's remove the animation for now to polish it better after:

Screenshot 2025-09-03 at 20 32 00
Screen.Recording.2025-09-03.at.20.37.58.mov

Positioning of the dropdown doesn't work; it should start right under the phone input, not over it. The width would ideally be the same as input's, but it's also fine as-is and something we can adjust after other changes.

Let's fit 4 countries visible at once so that it feels less crammed?

Multi lines have issues now:
image

Styling inheritance from parent styles is a bit all over the place 😅

Screenshot 2025-09-03 at 20 32 00
  • Background should be input background
  • Extra blue border under search input should be border color, or likely not needed at all?
  • Border colour, radius and thickness should be from input
  • Text color for dropdown and selected value should be same as input, now it's parent group's color
  • Selected/highlighted colour likely needs to use button styles to inherit them from the theme?

Text size doesn't apply to countrycode and carret, and the dropdown:

image

Finally, it would be good to match the editor with the same dropdown as in the frontend to allow true wysiwyg and control over design without publishing, but that's not a blocker for merging and can be a follow-up:

image

Test form:

<!-- wp:group {"align":"wide","className":"is-style-section-3","style":{"elements":{"link":{"color":{"text":"#9c005f"}}},"color":{"text":"#9c005f"}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide is-style-section-3 has-text-color has-link-color" style="color:#9c005f"><!-- wp:jetpack/contact-form {"variationName":"default"} -->
<div class="wp-block-jetpack-contact-form"><!-- wp:jetpack/field-email {"required":true} -->
<div><!-- wp:jetpack/label {"label":"Email"} /-->

<!-- wp:jetpack/input {"placeholder":"Placeholder","textColor":"accent-3","style":{"border":{"width":"2px","color":"#F6CFF4","radius":{"topLeft":"7px","topRight":"7px","bottomLeft":"7px","bottomRight":"7px"}},"color":{"background":"#fffdf2"},"elements":{"link":{"color":{"text":"var:preset|color|accent-3"}}}}} /--></div>
<!-- /wp:jetpack/field-email -->

<!-- wp:jetpack/field-telephone {"showCountrySelector":true,"default":"TH"} -->
<div><!-- wp:jetpack/label {"label":"Phone number"} /-->

<!-- wp:jetpack/phone-input {"placeholder":"Placeholder","textColor":"accent-3","style":{"border":{"width":"2px","color":"#F6CFF4","radius":{"topLeft":"7px","topRight":"7px","bottomLeft":"7px","bottomRight":"7px"}},"color":{"background":"#fffdf2"},"elements":{"link":{"color":{"text":"var:preset|color|accent-3"}}}}} /--></div>
<!-- /wp:jetpack/field-telephone -->

<!-- wp:jetpack/button {"element":"button","text":"Contact Us","lock":{"remove":true}} /--></div>
<!-- /wp:jetpack/contact-form --></div>
<!-- /wp:group -->

@CGastrell CGastrell force-pushed the add/forms-fancy-country-dropdown branch from 8407703 to aa403a3 Compare September 3, 2025 20:55
@CGastrell CGastrell requested review from simison and a team September 5, 2025 19:22
@CGastrell
Copy link
Contributor Author

@simison Thanks for the thorough review! Super helpful!

I don't think we need this sidebar setting since the dropdown in canvas already works well for setting the default:

Fair enough, I was about to ask about it. Removed.

Carret needs better centering, and let's remove the animation for now to polish it better after:

I adjusted the position, I think it sits better now.

Positioning of the dropdown doesn't work; it should start right under the phone input, not over it. The width would ideally be the same as input's, but it's also fine as-is and something we can adjust after other changes.

Position and dimensions are a bit tricky since it's absolute, not much relativity can be applied, so we're a bit stuck to hardcoded values. But I've added some CSS rules to try and use the space a bit better. Width is now set to max-content but limited to 75vw so we don't overflow the page.

Let's fit 4 countries visible at once so that it feels less crammed?

Good!

Multi lines have issues now:

With the above fixes this now only affects mobile views, but desktop displays show a better layout. Added flex alignment to top for the extreme cases
image
image

Styling inheritance from parent styles is a bit all over the place 😅

Yes! Another tricky scenario. We're trying to inherit as much as possible, but sometimes the backgrounds and colors can come from different places, becoming even transparent when a simple div wrapper shows up (KeyboardShortcuts for example). I've adjusted a bit, but in the end we'll need to make some compromises.

  • Background should be input background

As seen on the above screenshots, this is now inheriting from either the input background or the set styles.

  • Extra blue border under search input should be border color, or likely not needed at all?

Changed to a subtle "separator" border with neutral color. We can work on it, see if we can inherit it.

  • Border colour, radius and thickness should be from input

I don't think this is a good idea. I think the combobox can (and should) be more controlled. It's a floating UI element and while we want it to blend in, it can come with some surprises. Happy to explore, I'll leave some examples of edgy cases, the second one doesn't look so bad:

image image
  • Text color for dropdown and selected value should be same as input, now it's parent group's color

Seeing the screenshots above, was that what you meant?

  • Selected/highlighted colour likely needs to use button styles to inherit them from the theme?

I still fail to find a reliable var, we can use some of the accent colors (1 through 6) or mimic the buttons, which use a preset variable on top of another (color: var(--wp--preset--color--base); background-color: var(--wp--preset--color--contrast))

Text size doesn't apply to countrycode and carret, and the dropdown:

Fixed! But I wonder if you also meant we should apply the font size to the scrollable list, that would be hard to adjust (back to the absolute position/dimension topic). Maybe we can settle for using a percentage of the font-size set for the input? Like .74em?

Finally, it would be good to match the editor with the same dropdown as in the frontend to allow true wysiwyg and control over design without publishing, but that's not a blocker for merging and can be a follow-up:

Done!

image

AE: __( 'United Arab Emirates', 'jetpack-forms' ),
GB: __( 'United Kingdom', 'jetpack-forms' ),
US: __( 'United States', 'jetpack-forms' ),
UY: __( 'Uruguay', 'jetpack-forms' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es el mejor país

lezama
lezama previously approved these changes Sep 8, 2025
@CGastrell CGastrell merged commit fbffda8 into trunk Sep 9, 2025
67 checks passed
@CGastrell CGastrell deleted the add/forms-fancy-country-dropdown branch September 9, 2025 16:06
CGastrell added a commit that referenced this pull request Sep 9, 2025
CGastrell added a commit that referenced this pull request Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Contact Form Form block (also see Contact Form label) Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Feature] Contact Form [Package] Forms [Tests] Includes Tests [Type] Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants