Skip to content

Commit

Permalink
Ignore enter when country search has no results
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed May 2, 2024
1 parent c8ba37c commit a404324
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 56 deletions.
26 changes: 13 additions & 13 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ var factoryOutput = (() => {
this.searchInput.addEventListener("click", (e) => e.stopPropagation());
}
_filterCountries(query, isReset = false) {
let isFirst = true;
let noCountriesAddedYet = true;
this.countryList.innerHTML = "";
const normalisedQuery = normaliseString(query);
for (let i = 0; i < this.countries.length; i++) {
Expand All @@ -2194,12 +2194,15 @@ var factoryOutput = (() => {
if (listItem) {
this.countryList.appendChild(listItem);
}
if (isFirst) {
if (noCountriesAddedYet) {
this._highlightListItem(listItem, false);
isFirst = false;
noCountriesAddedYet = false;
}
}
}
if (noCountriesAddedYet) {
this._highlightListItem(null, false);
}
this.countryList.scrollTop = 0;
this._updateSearchResultsText();
}
Expand Down Expand Up @@ -2300,16 +2303,13 @@ var factoryOutput = (() => {
prevItem.setAttribute("aria-selected", "false");
}
this.highlightedItem = listItem;
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
this.selectedCountry.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || ""
);
this.searchInput.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || ""
);
if (this.highlightedItem) {
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
}
if (shouldFocus) {
this.highlightedItem.focus();
}
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInput.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInput.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions react/demo/simple-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25657,7 +25657,7 @@
this.searchInput.addEventListener("click", (e) => e.stopPropagation());
}
_filterCountries(query, isReset = false) {
let isFirst = true;
let noCountriesAddedYet = true;
this.countryList.innerHTML = "";
const normalisedQuery = normaliseString(query);
for (let i = 0; i < this.countries.length; i++) {
Expand All @@ -25669,12 +25669,15 @@
if (listItem) {
this.countryList.appendChild(listItem);
}
if (isFirst) {
if (noCountriesAddedYet) {
this._highlightListItem(listItem, false);
isFirst = false;
noCountriesAddedYet = false;
}
}
}
if (noCountriesAddedYet) {
this._highlightListItem(null, false);
}
this.countryList.scrollTop = 0;
this._updateSearchResultsText();
}
Expand Down Expand Up @@ -25775,16 +25778,13 @@
prevItem.setAttribute("aria-selected", "false");
}
this.highlightedItem = listItem;
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
this.selectedCountry.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || ""
);
this.searchInput.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || ""
);
if (this.highlightedItem) {
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
}
if (shouldFocus) {
this.highlightedItem.focus();
}
Expand Down
26 changes: 13 additions & 13 deletions react/demo/validation-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25657,7 +25657,7 @@
this.searchInput.addEventListener("click", (e) => e.stopPropagation());
}
_filterCountries(query, isReset = false) {
let isFirst = true;
let noCountriesAddedYet = true;
this.countryList.innerHTML = "";
const normalisedQuery = normaliseString(query);
for (let i = 0; i < this.countries.length; i++) {
Expand All @@ -25669,12 +25669,15 @@
if (listItem) {
this.countryList.appendChild(listItem);
}
if (isFirst) {
if (noCountriesAddedYet) {
this._highlightListItem(listItem, false);
isFirst = false;
noCountriesAddedYet = false;
}
}
}
if (noCountriesAddedYet) {
this._highlightListItem(null, false);
}
this.countryList.scrollTop = 0;
this._updateSearchResultsText();
}
Expand Down Expand Up @@ -25775,16 +25778,13 @@
prevItem.setAttribute("aria-selected", "false");
}
this.highlightedItem = listItem;
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
this.selectedCountry.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || ""
);
this.searchInput.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || ""
);
if (this.highlightedItem) {
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
}
if (shouldFocus) {
this.highlightedItem.focus();
}
Expand Down
30 changes: 16 additions & 14 deletions src/js/intl-tel-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ export class Iti {
}

private _filterCountries(query: string, isReset: boolean = false): void {
let isFirst = true;
let noCountriesAddedYet = true;
this.countryList.innerHTML = "";
const normalisedQuery = normaliseString(query);
for (let i = 0; i < this.countries.length; i++) {
Expand All @@ -1422,12 +1422,16 @@ export class Iti {
this.countryList.appendChild(listItem);
}
//* Highlight the first item.
if (isFirst) {
if (noCountriesAddedYet) {
this._highlightListItem(listItem, false);
isFirst = false;
noCountriesAddedYet = false;
}
}
}
//* If no countries are shown, unhighlight the previously highlighted item.
if (noCountriesAddedYet) {
this._highlightListItem(null, false);
}
//* Scroll to top (useful if user had previously scrolled down).
this.countryList.scrollTop = 0;
this._updateSearchResultsText();
Expand Down Expand Up @@ -1580,23 +1584,21 @@ export class Iti {
}

//* Remove highlighting from other list items and highlight the given item.
private _highlightListItem(listItem: HTMLElement, shouldFocus: boolean): void {
private _highlightListItem(listItem: HTMLElement | null, shouldFocus: boolean): void {
const prevItem = this.highlightedItem;
if (prevItem) {
prevItem.classList.remove("iti__highlight");
prevItem.setAttribute("aria-selected", "false");
}
//* Set this, even if it's null, as it will clear the highlight.
this.highlightedItem = listItem;
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
this.selectedCountry.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || "",
);
this.searchInput.setAttribute(
"aria-activedescendant",
listItem.getAttribute("id") || "",
);
if (this.highlightedItem) {
this.highlightedItem.classList.add("iti__highlight");
this.highlightedItem.setAttribute("aria-selected", "true");
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
}

if (shouldFocus) {
this.highlightedItem.focus();
Expand Down

0 comments on commit a404324

Please sign in to comment.