From b19e0febfd40f32fe93b485a56a830129addb977 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Tue, 22 Mar 2022 18:40:59 +0100 Subject: [PATCH] support default value, plus better sorting --- index.html | 5 ++++- src/components/address-autocomplete/index.ts | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 180458f9..2ac94e59 100644 --- a/index.html +++ b/index.html @@ -25,10 +25,13 @@

***
diff --git a/src/components/address-autocomplete/index.ts b/src/components/address-autocomplete/index.ts index 0b5eab62..408f244b 100644 --- a/src/components/address-autocomplete/index.ts +++ b/src/components/address-autocomplete/index.ts @@ -24,6 +24,9 @@ export class AddressAutocomplete extends LitElement { @property({ type: String }) label = "Select an address"; + @property({ type: String }) + initialAddress = ""; + @property({ type: String }) osPlacesApiKey = import.meta.env.VITE_APP_OS_PLACES_API_KEY || ""; @@ -62,6 +65,7 @@ export class AddressAutocomplete extends LitElement { id: this.id, required: true, source: this._options, + defaultValue: this.initialAddress, showAllValues: true, tNoResults: () => "No addresses found", onConfirm: (option: any) => { @@ -124,7 +128,8 @@ export class AddressAutocomplete extends LitElement { ); }); - this._options.sort((a, b) => a.localeCompare(b)); + const collator = new Intl.Collator([], { numeric: true }); + this._options.sort((a, b) => collator.compare(a, b)); } // fetch next page of results if they exist