The content within React Material Tabs may move outside of the designated Container area, causing it to shift unexpectedly

I am trying to incorporate the Tabs Component into my React Website but I am facing an issue. The content intended for display in the red/blue Container is getting shifted to the bottom for the blue container. Upon investigation, it seems that the problem stems from the presence of the invisible red box, which somehow affects the placement of my content.

This is how the JSX appears:

        <div className='drinks'>
            <Header />
            <div className="drinks-tabs-wrapper">
                <Tabs value={tab} onChange={ (_, value) => setTab(value) }>
                    <Tab label='Drinks' style={{ color: 'white' }} />
                    <Tab label='Categories' style={{ color: 'white' }} />
                </Tabs>
                <div style={ getTabWrapperStyle('drinks') }>
                    { (!drinks || !drinkCategories) ? 
                    <CircularProgress size={ 100 } /> :
                    <div hidden={ tab !== 0 }>
                        { drinks.map(drink => (
                            <div key={ drink.id }>
                                <p>{ drink.id }</p>
                                <p>{ drink.name }</p>
                                <p>{ drink.price }</p>
                            </div>
                        ))}
                    </div> }
                </div>
                <div style={ getTabWrapperStyle('drinkCategories') }>
                { drinkCategories &&
                    <div hidden={ tab !== 1 }>
                        { drinkCategories.map(drinkCategory => (
                            <div key={ drinkCategory.id }>
                                <p>{ drinkCategory.name }</p>
                            </div>
                        ))}
                    </div> }
                </div>
            </div>
        </div>

The data for drinks and drinkCategories is retrieved from an API (hence the Loader)

The function getTabWrapperStyle responsible for applying CSS has the following structure:

    const getTabWrapperStyle = (tabName) => {
        if (tabName === 'drinks') {
            if (tab !== 0) {
                return {
                    "display": "flex",
                    "alignItems": "center",
                    "justifyContent": "center",
                    "height": "calc(100% - 50px)",
                    "background": "blue",
                    "overflowY": "scroll"
                }
            } else if (tab !== 1) {
                return {
                    "height": 0
                }
            }
        } else if (tabName === 'drinkCategories') {
            if (tab !== 0) {
                return {
                    "height": 0
                }
            } else if (tab !== 1) {
                return {
                    "display": "flex",
                    "alignItems": "center",
                    "justifyContent": "center",
                    "height": "calc(100% - 50px)",
                    "background": "red",
                    "overflowY": "scroll"
                }
            }
        }
    }

While the red box seems to be functioning correctly, there are issues with the blue one. The shifting problem can be seen in the images below:

[1

https://i.sstatic.net/8XTKU.png

Answer №1

The issue was ultimately identified as the presence of the display: flex property in the blue and red containers' CSS. By removing this property and working without it, all functions properly.

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

The useEffect hook in Next.js does not trigger a re-render when the route changes

I'm currently experiencing an issue with a useEffect inside a component that is present in every component. I've implemented some authentication and redirection logic in this component, but I've noticed that when using Next.js links or the b ...

Conceal the second click action within the anchor tag

Is there a way to hide the second click event on all anchor tags except those that trigger popupfun? I have a sample page set up. [Check out the JS Fiddle here][1] http://jsfiddle.net/ananth3087/LgLnpvf4/15/ Link Anchor Tags: The page includes two ...

Utilizing a switch to deactivate all currently active classes on individual div elements

I'm currently facing an issue with implementing a toggle feature in a particle manner. I have three divs with onclick events and each has a toggle CSS class. My goal is to ensure that when one div is clicked, if the others are active, they revert back ...

"Troubleshooting problem with padding-right in Internet Explorer when displaying background image within

Encountering a problem with the IE browser (all versions up to IE 10). Here's the issue. The text in the input box is overlapping its background image. Unable to place this image in the parent div due to the dynamic nature of the input box and other ...

Body displays overflow scrollbar for flexbox instead of individual elements

The Issue: When using flexbox with overflow in a full-size app layout (100% width, 100% height), the scrollbars fail to appear for overflow-y in Firefox, IE, or Edge. The problem is specific to these browsers as it displays correctly in Chrome. Instead of ...

Design a dynamic dropdown feature that is triggered when the chip element is clicked within the TextField component

Currently, I am facing difficulties in implementing a customized dropdown feature that is not available as a built-in option in Material UI. All the components used in this project are from Material UI. Specifically, I have a TextField with a Chip for the ...

What is the best way to utilize regex in converting this CSS block to LESS?

Currently undertaking the task of refining over 10,000 lines of CSS code. Instead of manually converting line by line, I aim to transform from this: -webkit-transition: .1s linear all; -moz-transition: .1s linear all; transition: .1s linear all ...

"The issue with jQuery not functioning properly is isolated to a particular HTML file

I'm encountering a strange issue with jQuery as a beginner. It seems that my jQuery code is not functioning properly on the HTML file I created for the website's homepage. Surprisingly, when I test the same jQuery code on a blank HTML file, it wo ...

Steps for building an HTML tree

Exploring HTML files can be daunting, especially for someone with limited experience in this field. I am seeking assistance to transform these files into a more readable format, represented as a tree structure with each tag on a separate line. However, des ...

Tips for creating a stylish database-inspired list

Although this may not be the typical query, I will remove it later today to avoid clutter with a non-code error question. However, I urgently require some assistance. My goal is to extract information from the question database and compile a list of questi ...

Troubleshooting Loading Issues for Static Files and PNG Images in C# .NET 6 with React.js

Currently, I'm utilizing Visual Studio 2022 net 6.0 to create a React project, specifically using the ASP.Net Core with React.JS template. Visual Studo 2022 Template For guidance on initiating a new React application, I referred to this tutorial: ht ...

The value entered for the `value` property on the <input> element is not valid

I keep receiving a warning that I am unable to resolve: There is an issue with the value passed to the prop value in the HTML tag. To fix this, you can either remove it from the element altogether or ensure that a string or number value is being assigne ...

What steps should be taken to refresh a page following an AJAX file upload?

I need some help creating a progress bar to track file uploads on my website. Here's what I have so far: HTML: <form action="upload/files.php" method="post" enctype="multipart/form-data" id="frmUpload"> <input type="file" name="upfile" ...

The issue of excess space surrounding images while utilizing Bootstrap 3

Hey there, I'm currently working on a website using Bootstrap 3 framework and I've run into a little snag. Whenever I add an image (just a regular one with an img tag), it seems to have some white space on both the left and right sides of the scr ...

Returning AJAX HTML Page Code (Duplicate)

I've been attempting to create a basic Search Bar, but when I try to send the data to PHP and use ALERT for testing purposes, it alerts back the entire HTML page content. Despite searching extensively, I couldn't find a solution. Here's my ...

Tips for resizing a navbar to match the image within it as the window size decreases

I'm having an issue with my navbar that contains both an image and a menu. Everything looks good when the window is maximized, but as soon as I start to resize it, the image and menu shrink while the navbar stays the same height. I've tried usin ...

Rendering React Router server-side with client-side session information

Currently, I am working with mozilla client-sessions in conjunction with express/node. My goal is to pass my session.user to the react-router within a standard * request. Despite my efforts and attempts, I keep encountering an issue where it becomes unde ...

Tips for maintaining value visibility even after the page is reloaded

I'm currently working on a React.js application that connects and subscribes to an MQTT broker. Everything works fine initially, retrieving values from the broker without any issues. However, whenever I reload the page, it temporarily displays a value ...

Excessive re-renders are causing constraints in React (Next JS) functionality

I am encountering an issue with the following code ( Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.) The objective is to include a span on each item except for the last one. What is the most effective approach ...

How can you customize gutter widths for specific rows in Bootstrap 3?

Currently, I am constructing my own website using Bootstrap 3 and have come across a challenge that I would like to address: My goal is to assign distinctive gutter widths to certain rows in my design. The remaining sections of the site will adhere to th ...