fix: Widget phone number input country undefined in onSelectCountry (#9457)
* fix: Widget phone number input country undefined in onSelectCountry * chore: Minor fix
This commit is contained in:
@@ -39,6 +39,9 @@
|
|||||||
v-on-clickaway="closeDropdown"
|
v-on-clickaway="closeDropdown"
|
||||||
:class="dropdownBackgroundClass"
|
: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"
|
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"
|
||||||
>
|
>
|
||||||
<div class="sticky top-0" :class="dropdownBackgroundClass">
|
<div class="sticky top-0" :class="dropdownBackgroundClass">
|
||||||
<input
|
<input
|
||||||
@@ -85,7 +88,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import countries from 'shared/constants/countries.js';
|
import countries from 'shared/constants/countries.js';
|
||||||
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
|
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 FormulateInputMixin from '@braid/vue-formulate/src/FormulateInputMixin';
|
||||||
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
||||||
|
|
||||||
@@ -93,7 +95,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
FluentIcon,
|
FluentIcon,
|
||||||
},
|
},
|
||||||
mixins: [mentionSelectionKeyboardMixin, FormulateInputMixin, darkModeMixin],
|
mixins: [FormulateInputMixin, darkModeMixin],
|
||||||
props: {
|
props: {
|
||||||
placeholder: {
|
placeholder: {
|
||||||
type: String,
|
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: {
|
methods: {
|
||||||
setContextValue(code) {
|
setContextValue(code) {
|
||||||
// This function is used to set the context value.
|
// This function is used to set the context value.
|
||||||
@@ -235,7 +245,26 @@ export default {
|
|||||||
this.scrollToFocusedOrActiveItem(this.focusedOrActiveItem('focus'));
|
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() {
|
onSelect() {
|
||||||
|
if (!this.showDropdown || this.selectedIndex === -1) return;
|
||||||
this.onSelectCountry(this.items[this.selectedIndex]);
|
this.onSelectCountry(this.items[this.selectedIndex]);
|
||||||
},
|
},
|
||||||
scrollToFocusedOrActiveItem(item) {
|
scrollToFocusedOrActiveItem(item) {
|
||||||
|
|||||||
Reference in New Issue
Block a user