Issues with the ReactJS dropdown menu persist despite attempts to fix the problem with

I've been trying to add a blur backdrop filter to my dropdown menu in a React JS project, but it just doesn't seem to work. It works perfectly fine with all other elements except this one.

What I'm looking for is to have the same blur effect as in the header applied to the dropdown menu. Here's an image of the problem

I really hope someone can help me figure this out. I've tried various approaches but nothing seems to be working.

This is the React code snippet:

function Header(){
    return(
        <div>
            <div className="Header">
                <div className="Header-Container">
                <img className="Logo" src={Logo} />
                    <div className="search-cont"><input type="search" id="site-search" name="q" placeholder="Search..."></input></div>
                    <NavItem >
                        <DropdownMenu/>
                    </NavItem>
                <img id="Basket" src={Basket}/>
                <img id="Profile" src={Profile}/>
                </div>
            </div>
        </div>
    );
}

function NavItem(props){
    const[open, setOpen] = useState(false);
    return(
        <div className="Category">
            <div onClick={() => setOpen(!open)}>
                All categories
                <img id="DownArrow" src={DownArrow}/>
            </div>

            {open && props.children}
        </div>
);
}
function DropdownMenu(){
    function DropdownItem(props){
        return(
        <div className="menu-item">
            {props.children}
        </div>
        );
    }
    return(
        <div className="dropdown">
            <DropdownItem>
                #Hits
            </DropdownItem>
        </div>
    );
}

And here is the SCSS code:

body{
  .Header {
    .dropdown{
      backdrop-filter: blur(5px) opacity(100%);
      background: #333333a5 0% 0% no-repeat padding-box;
      display: inline-block;
      box-shadow: inset 0px 0px 35px #c8c8c810, 0px 3px 30px #0000004D;
      border: 1px solid #666666a8;
      border-radius: 15px;
      z-index: 10;
      position: absolute;
      top: 0vh;
      padding-top: 40%;
      padding-left: 20%;
      padding-right: 20%;
      padding-bottom: 40%;
      opacity: 1;
      .menu-item{
        height: 2vw;
        width: 12vw;
        margin-bottom: 5%;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        transition: all 0.4s ease-in-out;
        text-align: center;
        font: normal normal bold 18px Montserrat;
        letter-spacing: 1.2px;
        color: #FFFFFF;
        opacity: 1;
        cursor: pointer;
      }
      .menu-item:hover {
        background-color: #FFFFFF28;
      }
    }
    }

Answer №1

  • It's important to avoid declaring a React Component inside another React Component, as this can lead to it being destroyed and recreated with each render cycle.
function DropdownItem(props){
                    return(
                    <div className="menu-item">
                        {props.children}
                    </div>
                    );
                }

function DropdownMenu(){
            return(
                <div className="dropdown">
                    <DropdownItem>
                        #Хиты
                    </DropdownItem>
                </div>
            );
        }

Remember to keep your browser up to date, as some features like backdrop-filter may not be supported in all browsers.

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

What is preventing me from adjusting the padding of the mat-button?

Trying to adjust the default padding of a mat-button, but encountering issues with changing the component's style. Any suggestions on how to subscribe to the default padding (16px)? I've attempted modifying CSS properties to set the padding of a ...

JavaScript is failing to add items to an array

Attempting to add coordinates and user-specified data from a form to an array named "seatsArray". Here's the code snippet: <div> <img onLoad="shiftzoom.add(this,{showcoords:true,relativecoords:true,zoom:100});" id="image" src="plan1.bmp" wid ...

Firebase authentication with customizable dynamic URL routing

I am working on displaying a list of restaurants within a select tag, allowing users to easily select a restaurant. Here is what I have tried so far: class RestaurantSelector extends Component { this.state = { selectedRestaurant: "", } re ...

Transferring PHP Arrays to JavaScript with JQuery

I am facing an issue with redrawing markers (on Google Maps) from a database using jQuery form. Here is the code snippet: Index.html: var map; var data; function updateLocations(){ var post= $.post('php/getLoc.php',{table: "Auto"), functio ...

The module 'react' or its type declarations could not be located

Recently, I made the switch from Yarn version 1.x to 3.x (latest) and encountered some issues with Typescript in my project. Despite searching for solutions, none of the suggested fixes have resolved the problem that many others seem to be facing as well. ...

What is the best way to transform a string resembling JSON or a JS object into a valid JS object?

The specific String in question was originally part of a JavaScript object as shown below: var nameVal = "Jacob"; var favNumbersVal = "{\"firstNum\":0, \"secondNum\":1, \"thirdNum\":2}"; var aJSObject = { "name" = nameV ...

How to prevent the scroll bar from affecting a fixed div located at the top of the page

Check out this website: I am struggling with setting up a fixed menu div at the top and a content div below it on my site. I want the scroll bar to only apply to the content div and not the header div at the top, but I can't seem to figure out how to ...

Encountered an error when attempting to access the property "addOption" on an undefined object

Every time I try to implement search functionality, I keep running into this error: "cannot read property 'addOption' of undefined in JavaScript selectize." I have confirmed that my result array does contain data. This is my JavaScript code: ...

Attempting to invoke a static function from a imported ES6 module

Currently, I am utilizing Firefox 56 with the setting dom.moduleScripts.enabled enabled. This configuration allows me to engage with native ES6 modules seamlessly. In my Vue2 component, there is a method that I have defined: import StorageZonesAjaxMethod ...

Bring in data from a local JSON file into the state of a React

I am currently developing an application to help me practice utilizing routes, so I am starting with static, local test data in json format. This data is an object comprised of two arrays: folders and notes. My goal is for the initial state of my app to ...

Unable to emphasize the navigation menu for the current page within the Antd menu component

My objective is to use the ant design Menu component to highlight the navigation menu item of the current page. However, it seems that no matter which page I am on, the menu item does not get highlighted. Below is my code for the navigation menu. import ...

What is the syntax for defining "skills[]" in an AngularJS input field of type text?

When working with PHP, we often use name="skills[]" to retrieve data from a form as an array. How can this be achieved in AngularJS? For example, in PHP: <input type="text" name="skills[]" /> I am attempting to achieve the same functionality in An ...

When extracting data from an Excel sheet using JavaScript, the displayed value may appear different

I am currently in the process of working on a function to import Excel data into JSON objects on a website. To achieve this, I have implemented the XLSX.utils.sheet_to_json utility in JavaScript which converts all the data into JSON format. However, some o ...

Utilize the Image URL for training your Tensorflow.js application

I'm currently exploring how to use images sourced from the internet for training my neural network. I am utilizing an Image() object to generate the images and pass them to tensorflow. Despite my understanding that Image() should return a HTMLImageEle ...

The position of a jQuery element gets reset when both the show and stop animations are used

When I use jQuery's .position() to place an element, everything works fine. But as soon as I display an animation and then cancel it with an ajax call, the position of the element resets. function displayMessage(msg) { var $messageEl = $('#u ...

Setting a field as a date in a Community Connector: Best Practices

While exploring the reference page of Google Studio Community Connectors, I came across this specific example: { "name": "Created", "label": "Date Created", "dataType": "STRING", "semantics": { "conceptType": "DIMENSION" } } However, when a ...

Splitting each column in JavaScript using JSON.parse

While working on a JavaScript scraper for parsing JSON data, I encountered the challenge of separating each column with a value and data. After trying several methods, my code ended up looking like this: searchMangaFromElement(element) { var obj = JS ...

Mobile browsers are displaying fonts unevenly within tables

Currently in the process of developing a desktop site () that should function optimally on mobile browsers without the need for a separate mobile version. While mobile Safari scales up fonts in large text blocks, tables used for content are causing some is ...

Is there any extra step required in React and Express after installing an SSL certificate in cPanel?

Whenever I visit the site with the htaccess code below: RewriteEngine On RewriteCond %{HTTP_HOST} mypage\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://mypage.com/$1 [R,L] The page always redirects to /index.html, which is empty. ...

Activation code for the "Delete" key prompts the browser's return function - jQuery

I'm currently working on creating a digital keyboard that associates images with keycodes and adds them as spans after a keydown event. However, I have run into an issue with the DELETE feature. if (e.keyCode == 8) { $('span:last').remo ...