Skip to content

Create a setup-autocomplete modifier & usage#450

Merged
JulienVannier66 merged 10 commits intofeature/payment-requests-onboarding-reworkfrom
jv/vel-7085/create-a-setup-autocomplete-modifier
Jan 30, 2026
Merged

Create a setup-autocomplete modifier & usage#450
JulienVannier66 merged 10 commits intofeature/payment-requests-onboarding-reworkfrom
jv/vel-7085/create-a-setup-autocomplete-modifier

Conversation

@JulienVannier66
Copy link
Contributor

What does this PR do?

Implements a reusable Ember modifier that integrates Google Places Autocomplete with input elements for address autocompletion. The modifier automatically wraps input elements in a container, handles Google Maps API loading, and parses place results into structured address data.

Key features:

  • Flexible element targeting: works with direct input elements or container elements with nested inputs
  • Automatic DOM wrapper creation: wraps standalone inputs in a container div for proper Google Places styling
  • Smart cleanup: properly unwraps elements and removes pac-container on modifier teardown
  • Structured address parsing: converts Google Places results into standardized AutocompletionAddress format with address1, city, state, zipcode, country, and formattedAddress
  • International address support: handles various address formats including postal_town, postal_code_suffix, and country-specific components
  • Test-friendly: includes MockLoader for testing without actual Google Maps API calls
  • Configurable autocomplete options
  • Graceful error handling: handles missing callbacks and edge cases during cleanup

What are the observable changes?

Screencast.from.2026-01-26.11-59-50.webm

🧑‍💻 Developer Heads Up

⚡ Since we are using Ember Octane now:

  • Feel free to migrate existing components to Glimmer Components.
  • Write new ones exclusively in it.

Useful Resource : Ember Octane vs Classic Cheat Sheet

Good PR checklist

  • Title makes sense
  • Is against the correct branch
  • Only addresses one issue
  • Properly assigned
  • Added/updated tests
  • Added/updated documentation
  • Migrated touched components to Glimmer Components
  • Properly labeled

@JulienVannier66 JulienVannier66 self-assigned this Jan 26, 2026
@JulienVannier66 JulienVannier66 requested review from a team and phndiaye as code owners January 26, 2026 16:15
@JulienVannier66 JulienVannier66 requested review from nathalieArnoux and olxmpe and removed request for a team January 26, 2026 16:15
@linear
Copy link

linear bot commented Jan 26, 2026

Copy link
Member

@Miexil Miexil left a comment

Choose a reason for hiding this comment

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

👏 💪 🥳

state: '',
zipcode: '',
country: defaultCountry,
formattedAddress
Copy link
Member

Choose a reason for hiding this comment

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

this is never filled in ?

Copy link
Contributor Author

@JulienVannier66 JulienVannier66 Jan 27, 2026

Choose a reason for hiding this comment

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

The value is setup when the parseAddressComponents is called. It happens in handlePlaceChanged in the setup-autocomplete.ts

private handlePlaceChanged(place: GooglePlaceResult): void {
    if (!place.address_components) return;

    const formattedAddress = this.targetInput?.value ?? '';
    this.result = parseAddressComponents(place.address_components, formattedAddress); // here
    this.callback?.(this.result);
  }

The formatted address is the one generate by google map. When you click on a address, google map add the formatted value in the input value directly. So I need to have the input to get this value. This is why I don't do it in the address-parser directly

formattedAddress
};

const mapper: Record<AddressComponentType, (comp: GoogleAddressComponent) => void> = {
Copy link
Member

Choose a reason for hiding this comment

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

We are mapping all possible AddressComponentType yet AutocompletioinAddress is not using all of them ?

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 AddressComponentType is the type attribute returned by google map, the AutocompletioinAddress is the one we use on our side.

The is a example of what google returns

[
    {
        "long_name": "75013",
        "short_name": "75013",
        "types": [
            "postal_code"
        ]
    },
    {
        "long_name": "France",
        "short_name": "FR",
        "types": [
            "country",
            "political"
        ]
    },
    {
        "long_name": "Île-de-France",
        "short_name": "IDF",
        "types": [
            "administrative_area_level_1",
            "political"
        ]
    },
    {
        "long_name": "Paris",
        "short_name": "Paris",
        "types": [
            "administrative_area_level_2",
            "political"
        ]
    },
    {
        "long_name": "Paris",
        "short_name": "Paris",
        "types": [
            "locality",
            "political"
        ]
    },
    {
        "long_name": "Avenue d'Italie",
        "short_name": "Av. d'Italie",
        "types": [
            "route"
        ]
    },
    {
        "long_name": "69",
        "short_name": "69",
        "types": [
            "street_number"
        ]
    }
]

Copy link
Member

Choose a reason for hiding this comment

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

Nice 🥳

});

module('Element setup', () => {
test('it works with a text input element directly', async function (assert) {
Copy link
Member

Choose a reason for hiding this comment

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

do we want to verify the error case you are raising in the modifier when the target elem is not an input ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add these missing test cases

Copy link
Member

Choose a reason for hiding this comment

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

forgotten maybe ? can't see it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the two test case handles missing input element gracefully & handles missing input element in its children gracefully

@JulienVannier66 JulienVannier66 force-pushed the jv/vel-7085/create-a-setup-autocomplete-modifier branch from 7ab2d92 to b4bf65f Compare January 27, 2026 17:04
@JulienVannier66 JulienVannier66 merged commit c4ba078 into feature/payment-requests-onboarding-rework Jan 30, 2026
2 checks passed
@JulienVannier66 JulienVannier66 deleted the jv/vel-7085/create-a-setup-autocomplete-modifier branch January 30, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments