mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	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"
 | 
			
		||||
      :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"
 | 
			
		||||
    >
 | 
			
		||||
      <div class="sticky top-0" :class="dropdownBackgroundClass">
 | 
			
		||||
        <input
 | 
			
		||||
@@ -85,7 +88,6 @@
 | 
			
		||||
<script>
 | 
			
		||||
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) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user