Unusual mobile chrome behavior and erratic modal functionality

It has come to my attention that mobile users on Chrome/Android are experiencing some unusual behavior with modals. The autofocus feature is not working as expected, and the view keeps scrolling to the bottom.

This issue specifically occurs with modals that are placed at the end of a page.

Illustrative Examples

Experimentation Area

To showcase this problem, I have set up a sandbox environment (https://codesandbox.io/s/little-firefly-ruytgy?file=/src/App.vue).

Visual Demonstration

I have also created a short screencast for visual reference.

https://i.sstatic.net/F5zz7.gif

Code Snippet

Below is the code snippet from App.vue in our example:

<template>
  {/* Code snippet goes here */}
</template>
<script>
{/* JavaScript code block goes here */}
</script>

Temporary Fix

To address this issue temporarily, I have implemented a workaround: Prior to opening the modal, utilize

window.scroll(0,0);

This action forces the page to scroll to the top before opening the modal. However, it's not an ideal solution as users would have to scroll back down if they close the modal.

Answer №1

When it comes to CSS, I must admit that I'm not the most skilled, so there may be a more elegant solution out there than what I am about to suggest.

One issue I noticed is that the modal/dialog doesn't have a max-height set and ends up taking up all available height on the page. This results in a lengthy modal appearing both on desktop and mobile devices. One way to address this problem is by simply assigning it a max-height.

src/components/SimpleModal.vue
You can add a class (for example, .dialog) to the modal container (parent of DialogTitle) and then apply some CSS rules to it.

<style scoped>
// Tailwind appears to be applying the following rules:
// margin-top: 2rem;
// margin-bottom: 2rem;
// Take control of this as necessary and apply it manually

.dialog {
  --dialog-margin-y: 2rem;
  --dialog-max-height: 100vh;
  margin-top: var(--dialog-margin-y);
  margin-bottom: var(--dialog-margin-y);
  max-height: calc(var(--dialog-max-height) - calc(2 * var(--dialog-margin-y)));
  overflow-y: auto; // This is needed since we're setting a max-height
}
</style>

By implementing these rules, here are the outcomes I've observed:

Desktop https://i.sstatic.net/ZStVk.gif

Mobile https://i.sstatic.net/XSpnh.gif

I've also included a screenshot taken from my Android device for reference.

https://i.sstatic.net/VsID1.gif

Answer №2

When your modal pops up as you scroll to the bottom of the page, it may end up appearing off-screen with no space below for it to display properly. In this case, the modal will be positioned higher on the screen so that its content is still visible at the bottom of the viewport.

To work around this issue, consider setting a fixed height or a maximum height for the modal based on the view height.

Add the following CSS to your modal container: max-height: calc(100vh - 64px) and overflow-y: auto.

With these styles applied, your modal will take up a maximum of 100vh - 64px in screen height and any overflow content will be scrollable within the modal.

This solution helps prevent potential UI bugs in the future, such as modal heights exceeding page heights and causing layout issues.

.modal-container {
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}

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

Enable automatic playback of HTML5 video with the sound on

I want to add an autoplay video with sound on my website, but I'm running into issues with newer browsers like Chrome, Mozilla, and Safari blocking autoplay if the video doesn't have a 'muted' attribute. Is there a clever HTML or Javas ...

Recent Google algorithm changes impact websites built on AngularJS and JavaScript

Exciting news from Google today (May 28, 2014) - JavaScript content will now be rendered by the Googlebot itself! This means there's no need to worry about serving pre-rendered pages just for crawling purposes. You can find out more details on this an ...

Unusual behavior observed when React updates state

I am currently facing an issue where I am trying to update the state of my components through a child component, but for some reason the callback function is not registering the updated state. Method (loadModuleContent) export default class LayoutPag ...

The XMLHttpRequest function consistently comes back as undefined

Currently, I am working on the MDN tutorial about 'XMLHttpRequest'. Unfortunately, when trying to use request.open('GET', url) with a txt file from my local directory, it is returning undefined. I have checked both the url and request i ...

Tailwind-rn appears to be idle and unresponsive

I've been troubleshooting the implementation of tailwind-rn on my app without success. Despite trying various suggestions from different sources, I still haven't been able to identify the issue. The CSS files and JSON are generated correctly when ...

What is the best way to retrieve error messages from a transaction with ethers.js?

Incorporating a custom error in my Solidity contract: error Documents__AlreadyExist(string hash); The modifier I utilize is as follows: modifier alreadyExist(string memory hash) { if (s_documentsHashes[hash]) { revert Documents__AlreadyExi ...

Put "1" at both the beginning and end of an Array

I am working on a function that adds a "1" to the beginning and end of an array. This is the code I have attempted: var addTwo = function(array) { var myArray = array; var arrayLength; arrayLength = array.unshift(1); arrayLength = arra ...

Collaborating on search suggestion functionality

In my search suggestion script, the results are dynamically updated as the user types. My goal is to make it so that when a user clicks on a suggestion, they are redirected to the following page: searchPage.php?user_query=what the user has typed in the inp ...

Direct your attention towards the specific target div element using the get function

I need assistance with a webpage where items are listed using unique ids. I want the page to scroll up or down, depending on which link the user clicks, to find the element with the id specified in the address bar as foo=or2. Additionally, I would like the ...

Indicate the initial position of the scroll bar

Currently, I am working on implementing scrolling functionality and attempting to start it at a specific element based on a given id. This is how my html code looks like: <div class="list-wrapper" style="max-height:350px;overflow-y:scroll" > < ...

How can you include a comma between two objects within a string, excluding the last object, using JavaScript?

I have a string object stored in a variable passed from another class. My question is how can I add a comma between two objects, excluding the last object? Below is my code snippet: { "id":"57e4d12e53a5a", "body":"asdas", "publishe ...

Ajax response values overlap

I am developing an application that requires multiple Ajax requests, but I encountered a problem where I am receiving the same response values for both requests. Each request must include a data field called activityCode, yet I keep getting the value of Sc ...

What is the best way to show JavaScript output with span style?

I have added a translation feature that allows users to switch paragraphs to French when clicked. Each paragraph now has the first word wrapped in a span with a CSS class that enlarges and colors the text. However, I am facing an issue where when switchi ...

Unable to substitute a value using the useState hook in React

Whenever I click a key, I attempt to update the value of a variable but it appears not to be working as intended. ↓ The current implementation is not effective and needs improvement import React, { useState, useEffect } from 'react'; const Li ...

Swap the image (either the last or first child) within a div when it is hovered over

I have multiple Div's on my webpage and I am looking to change the color and image when a mouse hovers over them. Changing the text color from grey to blue is quite simple. CSS #div1:hover{color:#0000CC} If I want to change an image, I can achieve ...

Dynamically generate <router-link> elements by iterating over routes with Vue-router

I'm looking to iterate over my routes using v-for to dynamically create <router-link>s in the template section. Currently, I'm unsure how to access the router parameter, defined in main.js, within the template section of my jvds-navigation ...

What is the best way to target the nth-child() of a slotted element within a web component that utilizes multiple uniquely named slots?

I am struggling to select the second slotted item in a specific slot using slot[name=foo]::slotted(:nth-child(2)){, but it's not behaving as I anticipated. Even though the first foo slot is styled with green, the second one doesn't follow suit. ...

Tips for managing a Vuex array in Vue.js

I'm a novice in the field of web development and seeking guidance on extracting all the titles from objects within an array. I have a list of products retrieved through an axios request. The next task involves processing this array within a Vue compon ...

The $scope variable is missing from the DOM

I've been trying to implement ng-repeat with AngularJS, but I'm having trouble getting the scope result in my DOM. Is there something wrong that anyone can spot? I've spent hours troubleshooting this and no matter what I do, "players" always ...

Attempting to insert an element after the .load event has been triggered

I have been attempting to update the contents of ".myShop" after it's loaded from an external XML file, but without success. I believe my timing is correct, but I suspect that a loaded element may not be part of the DOM? Here's what I'm exp ...