Skip to content
Open
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
13 changes: 13 additions & 0 deletions src/components/vue-tel-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ describe('Props', () => {
expect(wrapper.find('.vti__dropdown-item > .vti__flag.au').element.parentElement.getAttribute('class')).toContain('preferred');
})
});

it('does not show preferred countries twice', () => {
const wrapper = shallowMount(VueTelInput, {
props: {
preferredCountries: ['AU'],
},
});

wrapper.vm.$nextTick(() => {
var countryList = wrapper.vm.sortedCountries.filter((c) => c.iso2 == 'AU')
expect(countryList.length).toBe(1);
})
})
});
describe(':validCharactersOnly', () => {
// TODO
Expand Down
4 changes: 3 additions & 1 deletion src/components/vue-tel-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@
const preferredCountries = getCountries(props.preferredCountries)
.map((country) => ({ ...country, preferred: true }));

const countriesList = [...preferredCountries, ...filteredCountries.value] as Array<CountryObject & { preferred: boolean }>
const filteredCountriesWithoutPreferred = filteredCountries.value.filter((country) => !preferredCountries.some((c) => c.iso2 == country.iso2))

const countriesList = [...preferredCountries, ...filteredCountriesWithoutPreferred] as Array<CountryObject & { preferred: boolean }>
if (!props.dropdownOptions.showSearchBox) {
return countriesList
}
Expand Down