Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/templates/_components/app/address-region-field.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,24 @@
});
}
"
{# Use h-0/overflow-hidden instead of x-show (display:none) or invisible (visibility:hidden)
so Chrome mobile can still autofill the input inside — it skips both display:none and
visibility:hidden inputs. #}
:class="currentRegions.length > 0 ? '' : 'h-0 overflow-hidden'"
>
<div x-show="currentRegions.length > 0">
{% include 'foster-checkout/_components/base/input-select-searchable' with {
context: context,
id: 'administrativeArea',
model: 'administrativeArea',
name: 'administrativeArea',
options: 'initialRegions',
eventName: 'addressregions',
fallbackOptions: fallbackOptions,
label: 'addressFields.stateLabel'|t('foster-checkout'),
placeholder: 'addressFields.select'|t('foster-checkout'),
required: true,
value: address ? address.administrativeArea : '',
errors: errors.administrativeArea ?? [],
autocomplete: 'address-level1'
} %}
</div>
{% include 'foster-checkout/_components/base/input-select-searchable' with {
context: context,
id: 'administrativeArea',
model: 'administrativeArea',
name: 'administrativeArea',
options: 'initialRegions',
eventName: 'addressregions',
fallbackOptions: fallbackOptions,
label: 'addressFields.stateLabel'|t('foster-checkout'),
placeholder: 'addressFields.select'|t('foster-checkout'),
required: true,
value: address ? address.administrativeArea : '',
errors: errors.administrativeArea ?? [],
autocomplete: 'address-level1'
} %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
@keydown.enter.prevent="open ? selectActiveOption() : toggleListbox()"
@keydown="onTriggerKeydown($event)"
@input="onTriggerInput($event)"
@change="onTriggerInput($event)"
class="w-full py-[11px] pl-3 pr-10 rounded-lg cursor-default border bg-white text-left focus:!ring-0 focus:!outline-none transition-color duration-300 caret-transparent"
:class="errors.length ? 'border-red-500 focus:border-red-500' : 'border-gray-250 focus:border-black'"
aria-haspopup="listbox"
Expand Down
12 changes: 12 additions & 0 deletions src/web/assets/checkout/dist/js/alpine.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ const SearchableSelect = (props) => {
if (input && input.value && !this.selectedOption) {
this.selectByValue(input.value);
}

// Auto-select if there's only one option
if (!this.selectedOption && o.length === 1) {
this.selectedOption = o[0];
}
});
});

Expand All @@ -147,6 +152,13 @@ const SearchableSelect = (props) => {
})
}
});

// Auto-select if there's only one option (deferred so watchers are active)
this.$nextTick(() => {
if (!this.selectedOption && this.options.length === 1) {
this.selectedOption = this.options[0];
}
});
},

/**
Expand Down
Loading