Skip to content

Commit

Permalink
enable search icon slot, add search placeholder & "possible" in phone…
Browse files Browse the repository at this point in the history
…Object
  • Loading branch information
waveo-wangxiao committed Apr 5, 2024
1 parent bbe4ae2 commit 38769f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/components/vue-tel-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
ref="refList"
:class="['vti__dropdown-list', data.dropdownOpenDirection]"
role="listbox">
<input v-if="dropdownOptions.showSearchBox"
:class="['vti__input', 'vti__search_box']"
aria-label="Search by country name or country code"
:placeholder="sortedCountries.length ? sortedCountries[0].name : ''"
type="text"
v-model="data.searchQuery"
@click.stop />
<div v-if="dropdownOptions.showSearchBox" class="vti__search_box_container">
<slot name="search-icon"></slot>
<input :class="['vti__input', 'vti__search_box']"
aria-label="Search by country name or country code"
:placeholder="dropdownOptions.searchBoxPlaceholder || (sortedCountries.length ? sortedCountries[0].name : '')"
type="text"
v-model="data.searchQuery"
@click.stop />
</div>
<li v-for="(pb, index) in sortedCountries"
role="option"
:class="['vti__dropdown-item', getItemClass(index, pb.iso2)]"
Expand Down Expand Up @@ -296,6 +298,7 @@
countryCode: result?.country,
formatted: data.phone,
valid: result?.isValid(),
possible: result?.isPossible?.(),
nationalNumber: result?.nationalNumber,
}
Expand All @@ -307,6 +310,7 @@
&& (props.ignoredCountries.length || props.onlyCountries.length)
&& !findCountry(result.country)) {
meta.valid = false;
meta.possible = false;
result.country = null;
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export type PhoneMeta = {
country: PhoneNumber['country'],
countryCode: PhoneNumber['country'],
valid: boolean,
formatted: string
possible: boolean,
formatted: string,
nationalNumber: string
};

Expand All @@ -30,6 +31,7 @@ export interface DropdownOptions {
showDialCodeInSelection?: boolean
showFlags?: boolean
showSearchBox?: boolean
searchBoxPlaceholder?: string
tabindex?: number
}

Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export const allProps = [
description: 'Show country search box',
inDemo: true,
},
{
name: 'dropdownOptions.searchBoxPlaceholder',
default: '',
type: String,
description: 'Placeholder for the search box',
inDemo: false,
},
{
name: 'dropdownOptions.tabindex',
default: 0,
Expand Down

0 comments on commit 38769f1

Please sign in to comment.