I am curious as to why my React demo app's parent tree is interpreting the height setting of 100% as 100vh instead

I am currently developing a web application and I want to implement a feature where pressing the hamburger button will cause the side drawer to slide the entire content to the right.

In the following link, you can see a dummy component called "Main" that represents any content placed between the header and footer.

At the Layout Component's grid, the main section should have an auto row height to make use of the available space after setting the header and footer. To ensure this functionality, I have set the height to 100% for all parent tags up to the root html.

If the height of any element inside Main exceeds the remaining viewport height (you can check on mobile view using your browser dev tools), the page breaks with content overflowing beyond the total height. The Backdrop and SideDrawer will not cover the entire page as before, leaving some parts uncovered.

I want the behavior such that when the main content extends beyond the 100% height limit, everything gets pushed down and the browser recognizes the content within the 100% height calculation.

Why is this happening? What mistake am I making?

I will include my sidedrawer and Layout components here so you can test this small demo here

import React, { useState } from "react";
import "./Layout.scss";
import Toolbar from "../../Components/Toolbar/Toolbar";
import Footer from "../../Components/Footer/Footer";
import SideDrawer from "../../Components/Sidebar/SideDrawer";

const Layout = props => {
  const [toggler, setToggler] = useState(false);
  const buttonTogglerHandler = () => {
    setToggler(!toggler);
  };
  const cssClasses = [
    "Layout",
    toggler ? "Layout__slideOn" : "Layout__slideOff"
  ];
  return (
    <div className={cssClasses.join(" ")}>
      <Toolbar toggler={toggler} onToggled={buttonTogglerHandler} />
      <SideDrawer show={toggler} close={buttonTogglerHandler} />
      <main>{props.children}</main>
      <Footer />
    </div>
  );
};

export default Layout;
.Layout {
  height: 100%;
  width: 100%;
  display: grid;
  grid: {
    template-rows: 3rem auto 5rem;
    template-areas: "header" 
                    "main" 
                   "footer"
  }

&__slideOn {
animation: slideLayout 300ms forwards ease-in;
@keyframes slideLayout {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(80%);
  }
}
}

&__slideOff {
  animation: unslideLayout 300ms forwards ease-out;
  @keyframes unslideLayout {
  0% {
    transform: translateX(80%);
  }

  100% {
    transform: translateX(0)
  }
  }
}
  & main {
    grid-area: main;
  }

  & footer {
    grid-area: footer;
  }
}
import React, { Fragment } from "react";
import "./Sidebar.scss";
import Backdrop from "../../UI/Backdrop/Backdrop";
import CSSTransition from 'react-transition-group/CSSTransition';

const SideDrawer = props => {
  return (
    <CSSTransition
      in={props.show}
      mountOnEnter
      unmountOnExit
      timeout={300}
      classNames={{
        enterActive: "Sidebar__open",
        exitActive: "Sidebar__close"
      }}
    >
      <Fragment>
        <div className="Sidebar">sidebar</div>
        <Backdrop show={props.show} closeBackdrop={props.close} />
      </Fragment>
    </CSSTransition>
  );
};

export default SideDrawer;

.Sidebar {
  position: fixed;
  top: 0;
  left: -80vw;
  bottom: 0;
  width: 80vw;
  background-color: blue;
  opacity: .5;

  &__open {
    animation: openSidebar 300ms forwards ease-in;
    @keyframes openSidebar {
      0% {
        transform: translateX(0)
      }
      
      100% {
        transform: translateX(80%)
      }
    }
  }

  &__close {
    animation: closeSidebar 300ms forwards ease-out;
    @keyframes closeSidebar {
      0% {
        transform: translateX(0)
      }
      
      100% {
        transform: translateX(-100%)
      }
    }
  }
}

Answer №1

To ensure that my parent tree expands to 100%, I need to set it up until the div containing the .Layout class. Here, I should include the min-height property to make it expand beyond 100% of the screen above the component tree.

This setup allows the component tree, starting from the html up to one level higher than the Layout Component (which has a middle grid row with auto height), to extend this row to over 100% height when necessary:

  • If the total height of the app screen exceeds the viewport

  • It will also guarantee that the app occupies at least 100% of the viewport if the total height of the app is less than the viewport.

This approach ensures full coverage of the entire app, spanning from the header to the footer.

Find the correct implementation @ CodeSandBox

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

Tips for positioning items within div in relation to its parent div

After successfully positioning the "choose" button inside a div, I encountered an issue where it only functions properly when hovered over. This occurred while experimenting with hover and positioning on the div element. Without hovering, the 3 buttons app ...

Error: The function addProductPaymentResponse() is missing the mandatory argument 'paymentForOrderID'

In order to limit post requests, I need to check if a similar str(number) in the paymentForOrderID already exists in the ProductPayment model. #model.py class ProductPayment(models.Model): user = models.ForeignKey(User, on_delete=models.SET_NULL, nul ...

Comparing iPad and Desktop Devices

Working on the responsive site sandbox.mercomcorp.com, I encountered an issue where the CSS meant for an iPad device is affecting the desktop CSS. Shouldn't the iPad have its own separate media query from the desktop? Here's a snippet of the CSS: ...

How can I retrieve an updated object array within an extended class in JavaScript?

Hey everyone, I am new to working with ES6 classes. Currently, I am trying to inherit an initialized object (this._obj) with updated data in the class B, but I am encountering an issue where I am getting the length of the initialized object instead of the ...

Unable to access the redux store directly outside of the component

When trying to access my store from a classic function outside the component, I encountered an error while calling getState(): Property 'getState' does not exist on type '(initialState: any) => any' Below is the declaration and im ...

Difficulty with TypeScript when using dynamic keys to reference React components within an object

Typescript is raising an error stating that the expression of type 'string' cannot be used to index the object '{ bg: OverridableComponent<SvgIconTypeMap<{}, "svg">>; de: OverridableComponent<SvgIconTypeMap<{}, &q ...

Avoiding Backbone Routing Conflicts when Implementing CSS3 Targeting

I have implemented a CSS target to create some basic animation in my Backbone project. However, I am facing an issue where the method I am currently using adds a #banner to the URL, which Backbone tries to interpret as a route if users refresh the page aft ...

Add a stylish border to your image within a container of fixed width

I am facing a challenge with a fixed width DIV element. Inside this element, there is a second DIV containing only an IMG element. My goal is to add a border to the image without exceeding the boundaries of either of the enclosing DIV tags. Solution #1: ...

My CSS is giving me some trouble

Currently, I have 4 widgets with different sizes placed within a main div called #box. To center them, I reduced the width to about 60% and set margin left and right to auto. However, when I zoom out in my browser, the widget blocks move more to the left a ...

Difficulty filling height with Bootstrap 4 flex-grow

I am in need of creating a layout with a header div at the top (that can be filled with content), a footer div at the bottom, and a middle div with an adaptable height to fill the entire screen. Check out my code below: <div class="container-fluid p-0 ...

Space constraints within an li element

Is there a solution to resolve the unusual impact of margins/paddings? Check out this example on jsfiddle: jsfiddle. Here is the screenshot of the issue: i.imgur.com/64S8C.jpg. I want to eliminate any margins/paddings in the li element. ...

What is the best way to animate a three.js object to the right using GSAP without obstructing the surrounding HTML text?

As a newcomer to web design, I seek forgiveness if my question appears basic. I am working on an animated object in three.js that I want to move to the left side of the screen using GSAP. Additionally, I have a text "Hello" on the left side of the screen. ...

Implementing a date selector for HighChart StockChart in reactjs (no need for jQuery)

As a newbie to both highcharts and React applications, I've been exploring how to integrate a calendar popup into a date selection range within a stock chart without using jQuery. While I have found some examples that are close to what I want, such as ...

Is it possible to implement a hover animation within another hover animation in WordPress?

Trying to incorporate two hover animations for the images in my photo galleries. When hovering over an image, I want a text to appear in a black overlay, and then when hovering over that text, it should become underlined. Looking for something similar to ...

Effortless Searching with Material UI's AutoComplete Feature

Having trouble with the AutoComplete Material UI component, as it requires pressing Enter twice on form submission. I am looking for a solution that allows me to only select an option once and then be directed to another webpage. Check out the Submission ...

Having trouble setting up a twitter widget?

I have developed a custom jQuery plugin that displays a sidebar on the left for social media content. The variable below contains the source of the content. I am currently facing an issue while trying to integrate a Twitter feed using the widget, as it kee ...

Oops! React js material-table is throwing a TypeError because it's having trouble converting undefined or null to

{ title: 'Stores', field: 'Depolar', editComponent: props => ( <Select name="Depolar" type="text" value={that.state.selectedStores} multiple inp ...

Arranged Items according to the value of nested objects

Sorting an object based on the number of votes it has and then mapping over the sorted object can be a bit tricky, especially when trying to retain the original keys. const data = { "comment-1508872637211" : { "description" : "Blah", "votes" : 1 ...

Positioning the label for a Material-UI text field with an icon adornment when the shrink property is set

https://i.stack.imgur.com/E85yj.png Utilizing Material-UI's TextField, I have an Icon embedded within. The issue arises when the label "Your good name here" overlaps the icon instead of being placed beside it. This problem emerged after I included ...

Resetting filter and sort state in MUI DataGrid when receiving fresh data

Recently, I began using the mui DataGrid. I have integrated it into a page with a dropdown menu that fetches different data based on user selection and passes that new data to the rows prop. However, I have noticed an issue where if I apply a filter or sor ...