Country code dropdown causing CSS problem on mobile devices (intl-tel-input)

Hey there, I've been using this awesome library for displaying country codes and flags to our users. Check it out here: https://github.com/jackocnr/intl-tel-input

Everything was working perfectly on desktop, even when resizing the screen. But when I decided to test it on a mobile device with Android Chrome, that's when the issue popped up.

So here's the problem I encountered:

https://i.sstatic.net/YYZaH.png

Users are unable to select different countries because the scrolling functionality is hidden, and they can only see the default selected country.

I attempted to resolve this by using z-index:9999, but unfortunately, it didn't work.

Here's the CSS code I implemented:

.intl-tel-input .country-list {
    position: absolute;
    z-index: 9999;
    list-style: none;
    text-align: left;
    padding: 0;
    margin: 0 0 0 -1px;
    box-shadow: 1px 1px 4px rgba(0,0,0,0.2);
    background-color: white;
    border: 1px solid #CCC;
    white-space: nowrap;
    max-height: 200px;
    overflow-y: scroll;
 }

I'm puzzled as to why this issue only seems to occur on mobile devices. Any ideas on how to fix it?

Answer №1

Encountering a similar issue myself, especially when the input was displayed in a modal or dialog box.
When viewing on mobile, the dropdown menu seems to be appended to the <body> element at the bottom due to this behavior:
https://github.com/jackocnr/intl-tel-input/blob/v16.0.8/src/js/intlTelInput.js#L117

An alternative solution is to modify the container element by adjusting the dropdownContainer option.

Answer №2

Image display issue

I recently encountered a similar issue on my mobile device and found a solution involving JavaScript that may be helpful to others. Feel free to reference it.

I have implemented a function to handle clicks on the flag icon, which repositions the displayed list of countries. The code appears to be functioning as intended.

 iti = window.intlTelInput(inputPhoneNumber, intlTelInputOptions)
 iti.isMobile= false;
 $('.iti__selected-flag').click(function () {
   if ($('body.iti-mobile').length) {
       $('.iti--container').css('top', $(this)[0].getBoundingClientRect().top + 35 + 'px');
       $('.iti--container').css('left', $(this)[0].getBoundingClientRect().left + 'px');
   }
})

Answer №3

iti.isMobile = false;

        $(window).on('scroll', function() {
            positionItiContainer();
        });

        $('.iti__selected-flag').click(function () {
            positionItiContainer();
        });

        var positionItiContainer = function() {
            if ($('body.iti-mobile').length) {
                var phoneElement = document.getElementById('phone');
                var selectedFlag = document.querySelector('.iti__selected-flag');
                var phoneRect = phoneElement.getBoundingClientRect();
                var selectedFlagRect = selectedFlag.getBoundingClientRect();

                $('.iti--container').css('top', selectedFlagRect.bottom + 'px');
                $('.iti--container').css('left', selectedFlagRect.left + 'px');
            }
        };

Answer №4

Yes, the bug is present in the library as well. By inspecting the code, I noticed that the max-height of the dropdown has been altered. To fix this issue, you can override the max-height by including the following CSS:

.iti-mobile .intl-tel-input .country-list {
    max-height: 200px !important; 
}

Answer №5

Why not give it a shot?

iti__country-list{white-space:nowrap}

Answer №6

I found a simple solution that worked for me with just one line of code.

useFullscreenPopup: false 

This snippet shows how that part of my code is implemented

var iti = window.intlTelInput(input, {
  initialCountry: "auto",
  geoIpLookup: function(callback) {
    fetch("https://ipapi.co/json")
      .then(res => res.json())
      .then(data => callback(data.country_code))
      .catch(() => callback("us"));
  },
   utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/23.0.12/js/utils.js",
   useFullscreenPopup: false 
});

For additional details, check out https://github.com/jackocnr/intl-tel-input/blob/master/README.md

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the Spring MVC ModelAndView object being returned?

After clicking a link on a jsp page, I have a GET method that is instantiated as: HTML: <div class="panel accordion clearfix" id="dispdir"> <script type="text/javascript"> window.onload = function() { //showDirectorySe ...

Ways to fetch additional Product Cards using JSON and a nextPage parameter

I'm facing difficulties in nesting a fetch inside another fetch. I'm not sure if this is the correct approach, but my goal is to utilize Vanilla JavaScript to fetch another JSON from the nextPage URL within the JSON list when the "load more" butt ...

The most efficient method for creating a substantial amount of pre-existing HTML within the DOM using jQuery

This particular webpage layout showcases articles contributed by users. Our platform allows users to publish their articles, which are added to the top of the page instantly while also being saved to the database via AJAX. <div class = 'article-wr ...

Tips for positioning a canvas and a div element next to each other on a webpage

I have a canvas and a div element that I need to split in a 60% to 40% ratio. However, no matter what changes I make to the display settings, the div is always displayed before the canvas. The Div element contains buttons with color-changing properties fo ...

The Android webview fails to load the page, but the app successfully loads it when accessed through the

I'm experiencing an issue with my HTML5 mobile web app loading fine in a browser but getting stuck on an Android webview. We have implemented a splash screen before loading the web app, but the webview seems to be stuck on the splash screen and does n ...

How do I adjust the ul size to be proportionate to the header?

I have a list with corresponding hyperlinks in my code, and I am trying to make these elements the same size as the header. I attempted adding auto padding and height auto but it did not produce the desired result. Here is the HTML snippet: <header id ...

The function onClick does not function properly when used with the <p> element, but it works flawlessly with the <button> element

export function SignoutButton() { return ( <p onClick={() => signOut({ callbackUrl: "/" })}> <IoIosLogOut /> Logout </p> ); } I was struggling with a function in my next.js project that wasn't wo ...

Determine the selected option in the dropdown menu upon loading the page and when clicked

I am working on capturing the value of a drop-down list whenever it is changed or when the page loads. The aim is to display different div elements based on the selected option in the report field - either State or Year. Any assistance with this would be ...

What is the most effective method for integrating Bootstrap CSS into an Angular project?

When incorporating a Bootstrap CSS file into an Angular project that has already been added using yarn add <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2909d9d868186809382b2c6dcc3dcc3">[email protected]</a>, th ...

What is the best way to eliminate leading zeros in PHP when echoing SQL statements?

Being a front-end programmer on a team of three, my PHP/MySQL skills are fairly basic. However, our back-end programmer is going on vacation and we have a deadline to address a minor visual detail. Currently, we are working on a page that displays multiple ...

Does applying a style to an element that already has the same value result in a decrease in performance? Alternatively, do all browsers simply overlook it?

Assuming I have an element with the style top: 5px, and then I execute element.style.top = "5px";, will the browser readjust its position and trigger a layout again? Or does it recognize that there is no need to change anything? (Is this behavior specified ...

Viewing an image from a local file on a web browser

I am currently working on a project where I want the user to be able to select a local image that will then be displayed on the page. As someone who is new to web development, I did a lot of research and found some helpful information on StackOverflow. I t ...

Unraveling the onsubmit FormObject in an HTML form within the Google Sheets Sidebar: Tips and tricks

In the sidebar, I am setting up a form with 27 inputs to create new sheets based on various criteria. The form includes a text entry field and multiple groups of radio buttons and checkboxes. However, I am currently facing an issue when trying to create a ...

Performing multiple actions in an Android EditText

*I am working with an android EditText where I have added drawables on the left and right side. While I have successfully implemented click actions for the left and right drawables, I am facing difficulty in differentiating between single-click and double- ...

Result android connection

I am currently using android 5.0.1 and compiling my app with API 21. I am trying to establish a connection to Google Play services using the following code snippet: package com.example.getlocation2; import android.support.v7.app.ActionBarActivity; i ...

Take off the wrapping from the package

I need help with my code on how to remove the wrapper span tag without removing the text. <ul> <li> <a href="#"> </a> <ul> <li> <a href="#"> ...

Kik Card - Using Synchronous XMLHttpRequest within the Kik.js Script

Getting ready to create a mobile web app powered by Kik! First step, insert the Kik.js script at the bottom of your HTML page... <!-- add this script to your webpage --> <script src="http://cdn.kik.com/kik/2.3.6/kik.js"></script> Excel ...

Choosing a box will cause a dashed rectangle to appear when the mouse is selected

Whenever I try to select an option in my select box, a dotted rectangle appears. How do I remove this feature? https://i.sstatic.net/BzsL2.png I have noticed that many others are also facing the same issue. I tried updating my CSS with some properties ba ...

Failure in Bootstrap Typography #1 - Unable to locate proper class attribute values for uppercase and reverse transformations

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel= ...

Flashing Effect of Angular Ui-Bootstrap Collapse During Page Initialization

Below is the code snippet I've implemented to use the ui-bootstrap collapse directive in my Angular application. HTML: <div ng-controller="frequencyCtrl" style="margin-top:10px"> <button class="btn btn-default" ng-click="isCollapsed = ...