The React modal refuses to disappear, stubbornly clinging to the original component it sprang from

Hey there, I'm a beginner in learning React and I'm encountering an issue with my popup modal component. Even after showing the modal, I can still interact with and click on the main UI elements. Can anyone assist me with this problem?

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

     import React, { useState } from 'react';
    import styled from 'styled-components'
    // Other imports...

const Container = styled.div`
         background: white;
         // Styles...
`;

const InputSection= styled.div`
        width: 100%;
        min-width: 350px;
        // Other styles...
`;
// More styled components defined

const UserUi =function(){
    // Functionality for user UI
}

export default UserUi

Here is the modal component code snippet:

import React, { useState as UseState, useEffect as UseEffect ,useRef as UseRef} from 'react';
import styled from 'styled-components'
// Other imports...

const Background = styled.div`
  width: 100%;
  height: 100%;
  // Styles...
`;

// More styled components defined

export const msgbox = ({ showModal, setShowModal }) => {
    // Functionality for displaying modal
  
        return (
          <>
      {showModal ? (
        <Background onClick={closeModal} ref={modalRef}>
            // Modal content
        </Background>
      ) : null}
    </>
        
        )
    }


export default msgbox

I appreciate any help in resolving this issue. I've tried various methods to display the modal properly but haven't found a solution yet. Could it be related to how I set up my styled components or where I placed the modal component? Thank you in advance for your assistance.

Answer №1

The issue with the input tags overlapping the modal is due to the z-index property. By setting it to zero, this problem should be resolved.

For more information on CSS z-index Property, you can visit w3schools.com at https://www.w3schools.com/css/z-index.asp. (accessed November 22, 2020)

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

Why does replacing <input> with <TextField> in Material-UI & React cause the form submission to fail?

Recently, I encountered an issue with my CRUD Todo app's form for adding tasks. Initially built with a basic HTML input and button setup, I decided to enhance the design using Material-UI components. After introducing <TextField> in place of th ...

When a user right-clicks on certain words, the menu opens using JavaScript

Looking to implement a custom context menu that opens when specific words are right-clicked by the user in JavaScript. I have been searching for a solution for quite some time now. The word should be recognized based on an array of specific words. Can some ...

Safari iOS does not properly support responsive images when using srcset and sizes

I am facing an issue with the following code snippet: <img src="/img/footer/logo_white.png?v=2.0" srcset="/img/footer/logo_white.png?v=2.0 1x, /img/footer/logo_white2x.png?v=2.0 2x" > This ...

Dealing with React Native: Navigating App Store Rejections and Embracing IPv6

In my react-native client for a website, the login page offers two options: manually enter the login code or scan it using a barcode scanner. I have extensively tested the app on real devices and emulators, and it's functioning correctly. However, all ...

An innovative tool for discovering how different colors will complement each other

Design may not be my strong suit, but there are times when I need to add a border line or a shade of gray to a background color. Is there a tool available where I can specify background color: #343434 color: #asdfgh and visually see how it will look wit ...

Using a function as an argument to handle the onClick event

I have a function that generates a React.ReactElement object. I need to provide this function with another function that will be triggered by an onClick event on a button. This is how I call the main function: this._createInjurySection1Drawer([{innerDra ...

The CSS code designed to limit the display to only a two-line sentence is failing to work properly in Internet Explorer

I've implemented the following CSS code to ensure that the display sentence doesn't exceed 2 lines, with the remaining text being replaced by "...". .bell-notification-max-words-display { overflow: hidden; display: -webkit-box; ...

Utilizing the React-Redux useSelector in a traditional class-based component

Hello, I'm currently exploring React and encountering an issue with implementing the useSelector in a class component. I would really appreciate any assistance or guidance on this matter. Here is how the useSelector is structured: const userLogin = u ...

Ways to hide the value from being shown

I have integrated jscolor (from jscolor) to allow users to pick a color with an input field. However, I am facing issues in styling it as I'm unable to remove the hex value of the selected color and couldn't find any relevant documentation on av ...

Steps for Building and Exporting a Next.js Project Without Minification and Optimization

Is there a way to build and export a Next.js project without minifying and optimizing the output files? ...

Why is there a thin line still visible on the other sides when a transparent background is used, but only on mobile devices, with a curved border on one side?

Recently, I've delved into the world of creating CSS art and stumbled upon a peculiar issue with CSS borders that has left me puzzled. When I apply a border to only one side of an element with a transparent background and rounded edges, I notice a fa ...

The width of DIVs in Mac Safari exceeds that of other browsers

Encountering an issue that is specific to MAC Safari. Here's the code snippet: <div class="wrapper" style="max-width:1220px"> <div style="width:50%;display:inline-block">First</div> <div style="width:25%;display:inline-block"&g ...

What is preventing the input box from shrinking further?

I created a search box using CSS grid that is supposed to shrink when the page is resized. However, it doesn't seem to shrink as much as I expected it to. Here is how it appears when fully extended: https://i.stack.imgur.com/tPuCg.png And here is how ...

Incorporating pre-designed elements into the bottom section of my

I'm currently facing an issue while trying to integrate a footer content from a template into my slideout footer. The problem is that the template footer is currently spanning across the entire width of the page, and I am struggling to contain it with ...

How can Rails resize images for display on views?

Is there a way to resize an existing image to specific dimensions without creating multiple versions? Currently, I am using Carrierwave and Rmagick to upload images to my Amazon S3 storage bucket. It generates two versions of the image: the original and a ...

Changing the Theme in React with Material UI

Can someone assist me in dynamically changing the React Material UI theme? I have attempted to modify the theme properties upon button click, and although the console reflects that the theme properties are being altered, the change is not being reflected o ...

Position the typography component to the right side

Is there a way to align two typography components on the same line, with one aligned to the left and the other to the right? I'm currently using this code but the components are aligned next to each other on the left side. const customStyles = makeSt ...

How to centrally align text in list items using Bootstrap 5

Incorporating Bootstrap 5 into my project, I am facing a challenge with vertically aligning text in an li element. Despite trying various techniques mentioned in the Bootstrap documentation for middle/center alignment, none of them seem to be effective. I ...

What is the method used by React or Next to prevent the <a> tag from refreshing the page while still loading content?

I'm currently diving into the world of NextJS and utilizing the Link component from the 'next/link' package. One thing that has been puzzling me is how the <Link> component ultimately renders an <a> tag with a href='/tosomew ...

What could be causing my React useState not to update my components?

My understanding of React might be lacking, but I am facing an issue with updating a Component after the state has been asynchronously updated. const [appState, setAppState] = useState({ countries: null, languages: null }) useEffect(() ...