Problem with the placement of Google autocomplete dropdown

I'm currently utilizing the NgxAutocomPlace module within my Angular application. This module interacts with the Google Autocomplete API by generating a .pac-container to display autocomplete suggestions.

However, I'm facing an issue where on mobile devices, the dropdown appears above the input instead of below it, making it difficult for users to interact with. Here is a visual representation of the problem:

https://i.sstatic.net/kZg6j.jpg

Here is a snippet of my code:

<div class="container-indirizzo mb-3">
  <label>Indirizzo di consegna</label>
  <div class="inside-indirizzo">
      <div class="indirizzo">
        <input
          *ngIf="addressOptions !== null"
          type="text"
          class="form-control"
          required
          placeholder="es. Via Disraeli"
          formControlName="indirizzo"
          ngxAutocomPlace
          [options]="addressOptions"
          (selectedPlace)="addressChange($event)"
        />
      </div>
      <div class="civico" *ngIf="isCivico">
        <input type="text" class="form-control" formControlName="nciv" placeholder="N°" autofocus />
      </div>
  </div>
</div>

Is there a way to specify the position of the dropdown to appear under the <input> field?

EDIT 1:

The issue occurs when scrolling or on mobile devices when the virtual keyboard is active. The problem lies in the positioning of the pac-container when it's triggered.

EDIT 2:

I've attempted to adjust the position of the dropdown on Address change and scroll events, but it doesn't seem to be effective:

 const top = this.indirizzo.nativeElement.getBoundingClientRect().top ;
  const pacContainer = document.querySelector('.pac-container') as HTMLElement;
  if (pacContainer) {
    console.log(window.scrollY + top + 60);
    pacContainer.style.top = window.scrollY + top + 60;
  }

Where 'indirizzo' represents the div where the input is located.

EDIT 3:

The .pac-container is being generated under the <body>, so I believe moving it to be rendered under

<div class="indirizzo">
could resolve the issue...

EDIT 4:

SOLVED by setting the top position of the pac-container to a fixed distance from the top of the screen to the bottom of the input field. However, I'm still exploring a more optimal solution.

(For example, setting .pac-container top: 465px based on the height from the top of the screen to the end of the input field, which varies on different screens, leading to a poorly drawn dropdown on some devices.)

Answer №1

If you are utilizing Angular material, here's a helpful tip:

.pac-container {
    z-index: 100000;
}

For Bootstrap users, this tweak will come in handy:

::ng-deep .pac-container {
    z-index: 100000;
}

Answer №2

Maybe implementing something similar to this code after all the elements have finished loading could potentially resolve the issue.

const pacContainer = document.querySelector('.pac-container') as HTMLElement;
const body = document.body as HTMLElement;
const indirizzo = document.querySelector('.indirizzo') as HTMLElement;
const clone = pacContainer.cloneNode(true);
indirizzo.appendChild(clone);
body.removeChild(pacContainer);

.pac-container styling in CSS should include position: relative.

Answer №3

After encountering a similar problem while working with Bootstrap and Angular Material UI, I found a solution by utilizing the following CSS code.

body {
    background-color: #f4f4f4;
    font-family: Arial, sans-serif;
}

Answer №4

Give this a shot:

/deep/ .pack-container{
  z-index: 10000 !important;
  position: fixed !important;
}

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

Can CSS be used to target HTML elements that come after another regardless of their position in the document?

Is there a way to style any <h1> element(s) that come after an <h2> element using only CSS? I've searched through countless pages of CSS documentation, trying to figure out if it's possible to target specific elements that appear AFT ...

Navigating using Javascript library in Angular 2 framework

I am currently utilizing Parse, an external JS library, within Angular JS 2. Nevertheless, I am encountering issues when attempting to call the function gotoMain() from within a callback function of Parse. It appears that certain elements are not being l ...

Avoiding the use of a particular URL when using this.router.navigate() in AngularJs

In my angularJS registration form, I am using a bootstrap template for the design. The URL path to access the form page is http://localhost:4200/signup <form method="post" (submit)='register(username.value,email.value,password.value)'> ...

Switch up the current Slick Carousel display by utilizing a div element

We have implemented the slick carousel to show only one slide at a time within the <div class='item__wrapper'>. Beneath this are three items, and we want the slick carousel to update when any of these items are clicked. Issues Using item ...

Ways to update CSS using alternate classes without relying on !important

I have a generic form in my code that styles all my buttons uniformly: input[type="button"],put[type="button"]:active,input[type="button"]:hover { width: 172px; height: 37px; line-height: 2 !important; margin: 11px 0px 0px 0px; padding ...

After the component has been initialized for the second time, the elementId is found to be null

When working with a component that involves drawing a canvas chart, I encountered an issue. Upon initializing the component for the first time, everything works fine. However, if I navigate away from the component and return to it later, document.getElemen ...

Gather keyboard information continuously

Currently working with Angular 10 and attempting to capture window:keyup events over a specific period using RXJS. So far, I've been facing some challenges in achieving the desired outcome. Essentially, my goal is to input data and submit the request ...

Angular Tutorial: Modifying the CSS transform property of HTML elements within a component directly

Currently, I'm in the process of developing an analog clock for a project using Angular. My challenge is figuring out how to dynamically update the sec/min/hour handlers on the clock based on the current time by manipulating the style.transform prope ...

Tips for sending data other than strings in a GET request to a web API

When calling an asp.net mvc web api controller action from an angular 2 application, I have the ability to accept objects from the call using a post method. Here is an example: [Route("api/getItems")] [HttpPost] public ReturnObject GetItems(Da ...

Activate all chosen CSS circles

I'm currently working on creating a progress bar using CSS circles. The idea is that when you click on each circle in sequence (1, 2, 3), all three circles and the line connecting them will fill up with red color. If you then go back (3, 2, 1), the co ...

numbered navigation jquery plugin

Can anyone recommend a jQuery plugin or alternative solution for creating a navigation system for comments similar to YouTube? Here is the link for reference: Thank you in advance. ...

Ways to incorporate the CSS class name within the MUI createTheme palette color reference instead of using a hardcoded name

How can I dynamically insert a CSS class name inside the Material-UI(MUI) createTheme palette color instead of hardcoding it? const theme = createTheme({ palette: { primary: { light: "#66b53f", main: * ...

Show a directional indicator on hover in the date selection tool

I am currently using a datepicker that looks like this: https://i.sstatic.net/XsrTO.png When I hover over it, three arrows appear to change days or show the calendar. However, I would like to remove these arrows. Here is the code snippet: link: functi ...

Encountering Error: Unable to create new component as PriorityQueue is not recognized as a constructor

While trying to create a new component using Angular CLI with the command ng g c navbar, I encountered an unusual error message: core_1.PriorityQueue is not a constructor TypeError: core_1.PriorityQueue is not a constructor at new TaskScheduler (/h ...

A chosen class containing a nested class that utilizes the makeStyles function

Can someone explain how to target the 'element' when the root is selected? Here is the makeStyles code snippet: const useStyles = makeStyles(theme => ({ root:{ '&.selected': { } }, element: { } }) And h ...

The uncomplicated bar graph and its corresponding axis line up perfectly beside each other in an SVG diagram

I'm currently working on a stacked bar chart in my CodePen project found here: https://codepen.io/a166617/pen/qBXvzQd However, I am facing an issue where the graph is not aligned properly with the x-axis and y-axis lines. The barchart seems to be sli ...

Unable to locate the module from my personal library in Typescript

The Query Why is my ng2-orm package not importing or being recognized by vscode when I try to import Config from 'ng2-orm'; import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser&a ...

Unable to utilize first-child CSS to establish the display

I'm currently using WordPress and it's generating the following code: <aside class="left-hand-column"> <div class="textwidget"> <p></p> ...1 <div class="pdf-download"> <p> ... 2 <a href="http ...

The RxJS Map operator may struggle to detect changes in an array that has been

EDIT: My question has been flagged as a duplicate. Despite my efforts to search for a solution, I failed to consider the full context of the issue and wasted hours using incorrect keywords. I have acknowledged the helpful response provided once the mistake ...

The functionality of Bootstrap styles is not compatible with Code Igniter

I tried placing the bootstrap folder in the root folder and loading the styles in the header section of view files like this. Unfortunately, it didn't work as expected. Can someone please assist me in solving this issue? <link href="<?php e ...