I have a Flexbox container in a React app with flex-direction: row
. The container contains two tiles, both with flex: 1
. Each occupies 50% of the width as shown below. This is expected.
However, when the state of the component changes and only Tile 1
is rendered, it still occupies only 50% of the width, not expanding to take up the full width. When I wiggle the browser window a bit, Tile 1
expands to the full width. Note that the state of the component has not changed during the window resize, only that the tile now occupies the full width. I am thinking that I may have hit some React + Flexbox bug. Any ideas what this may be?
Unfortunately I am not able to reproduce this issue with a minimal example. Here's the live version of the minimal example that works perfectly! The source code is here.
The rendered HTML and CSS are effectively as simple as the following:
body {
font-family: Arial, Verdana, Helvetica, sans-serif;
}
.container {
display: flex;
flex-direction: row;
}
.content {
flex: 1;
min-width: 0;
margin-right: 4px;
padding: 4px;
height: 60px;
color: white;
background-color: #2196f3;
}
<div class="container">
<div class="content">
Tile 1
</div>
<div class="content">
Tile 2
</div>
</div>
The real code is further wrapped using react-measure and react-swipeable-views, but I don't think those are contributing to the issue.