diff --git a/app/javascript/widget/components/Form/PhoneInput.vue b/app/javascript/widget/components/Form/PhoneInput.vue
index 8a37d02c9..c7fafa916 100644
--- a/app/javascript/widget/components/Form/PhoneInput.vue
+++ b/app/javascript/widget/components/Form/PhoneInput.vue
@@ -39,6 +39,9 @@
v-on-clickaway="closeDropdown"
:class="dropdownBackgroundClass"
class="country-dropdown h-48 overflow-y-auto z-10 absolute top-12 px-0 pt-0 pl-1 pr-1 pb-1 rounded shadow-lg"
+ @keydown.up="moveSelectionUp"
+ @keydown.down="moveSelectionDown"
+ @keydown.enter="onSelect"
>
import countries from 'shared/constants/countries.js';
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
-import mentionSelectionKeyboardMixin from 'dashboard/components/widgets/mentions/mentionSelectionKeyboardMixin.js';
import FormulateInputMixin from '@braid/vue-formulate/src/FormulateInputMixin';
import darkModeMixin from 'widget/mixins/darkModeMixin';
@@ -93,7 +95,7 @@ export default {
components: {
FluentIcon,
},
- mixins: [mentionSelectionKeyboardMixin, FormulateInputMixin, darkModeMixin],
+ mixins: [FormulateInputMixin, darkModeMixin],
props: {
placeholder: {
type: String,
@@ -185,6 +187,14 @@ export default {
);
},
},
+ watch: {
+ items(newItems) {
+ if (newItems.length < this.selectedIndex + 1) {
+ // Reset the selected index to 0 if the new items length is less than the selected index.
+ this.selectedIndex = 0;
+ }
+ },
+ },
methods: {
setContextValue(code) {
// This function is used to set the context value.
@@ -235,7 +245,26 @@ export default {
this.scrollToFocusedOrActiveItem(this.focusedOrActiveItem('focus'));
});
},
+ adjustSelection(direction) {
+ if (!this.showDropdown) return;
+ const maxIndex = this.items.length - 1;
+ if (direction === 'up') {
+ this.selectedIndex =
+ this.selectedIndex <= 0 ? maxIndex : this.selectedIndex - 1;
+ } else if (direction === 'down') {
+ this.selectedIndex =
+ this.selectedIndex >= maxIndex ? 0 : this.selectedIndex + 1;
+ }
+ this.adjustScroll();
+ },
+ moveSelectionUp() {
+ this.adjustSelection('up');
+ },
+ moveSelectionDown() {
+ this.adjustSelection('down');
+ },
onSelect() {
+ if (!this.showDropdown || this.selectedIndex === -1) return;
this.onSelectCountry(this.items[this.selectedIndex]);
},
scrollToFocusedOrActiveItem(item) {