I have a simplified version of an issue I am having. I have a container which I put items into. The container is set up as display: grid
and I want it to always fill all available vertical space regardless of what is in it.
For illustration I have a simple CodeSandbox here. My question is :
- Why does the container (in grey) not fill all available space despite setting
height: 100%
? (I also triedheight: 100vh
here but it ended up stretching the elements inside also) - When I remove something from the container (i.e. Click "Remove Card" button), why does it shrink ?
import Paper from "@material-ui/core/Paper";
import Button from "@material-ui/core/Button";
import { makeStyles } from "@material-ui/styles";
import React, { useState } from "react";
const useStyles = makeStyles({
cardContainerRootStyle: {
gridTemplateColumns: "repeat(auto-fit, minmax(348px, 1fr))",
justifyItems: "center",
display: "grid",
gridGap: "1rem",
margin: "0 auto",
padding: 15,
height: "100%"
}
});
export default function App() {
const styles = useStyles();
const [cardCurrentlyDisplayed, setCardCurrentlyDisplayed] = useState([
<Paper
style={{ minHeight: "200px", minWidth: "200px", backgroundColor: "blue" }}
/>
]);
return (
<>
<Button variant="outlined" onClick={() => setCardCurrentlyDisplayed([])}>
Remove Card
</Button>
<Paper
style={{ backgroundColor: "grey" }}
square={true}
classes={{
root: styles.cardContainerRootStyle
}}
>
{cardCurrentlyDisplayed}
</Paper>
</>
);
}
Updated 9th March 2020 - Solution - https://codesandbox.io/s/minimumheightgrid-nh2oq