Cheetah
Cheetah

Reputation: 14379

Polymer iron-list with flexbox

I'm struggling to get iron-list to play nice with iron-flex-layout and paper-card. What I am hoping for is for the paper-card to flex expand on both axis to cover the page (with its margin as a bumper) and then for the iron-list to expand vertically in its container to show my iron-list with all its "virtual list" magic.

Where am I going wrong?

<script src="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/webcomponentsjs/webcomponents-lite.min.js"></script>

<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/paper-card/paper-card.html">
<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/paper-progress/paper-progress.html">
<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/iron-list/iron-list.html">

<style is="custom-style" include="iron-flex iron-flex-alignment iron-positioning">
  body {
    margin: 0;
    height: 100vh;
  }

  paper-card {
    margin: 1em;
  }

  iron-list {
    border-bottom: 1px solid #f00;
    border-top: 1px solid #000;
  }
</style>

<div class="vertical layout">
  <template is="dom-bind" id="app">
    <paper-card heading="My paper card" class="flex">
      <div class="card-content layout vertical">
        <div>[[listing.length]]</div>
          <iron-list items="[[listing]]" class="flex">
            <template>
              <div class="layout horizontal">
                <div>[[item.name]]</div>
                <div>[[item.value]]</div>
              </div>
            </template>a
          </iron-list>
      </div>
    </paper-card>
  </template>
</div>

<script>
  "use strict";

  window.addEventListener('WebComponentsReady', e => {
    app.listing = [];
    for (var i = 0; i < 100; i++) {
      app.push('listing', { name: i, value: i });
    }
  });
</script>

Fiddle: https://jsfiddle.net/4czLkjfj/

Upvotes: 1

Views: 473

Answers (1)

Michael Benjamin
Michael Benjamin

Reputation: 371213

You have the body element set to height: 100vh.

However, this height isn't being inherited by the flex container one-level down.

One solution is to add display: flex to body. This creates a flex container which automatically applies align-items: stretch to the children.

body {
  display: flex;
  align-items: stretch; /* initial setting; can be omitted */
}

div.vertical.layout {
  flex: 1; /* full width */
}

revised fiddle

Another solution would be to simply tell the flex container to inherit the parent's height.

div.vertical.layout {
  height: 100%;
}

revised fiddle


Revised solution based on feedback in the comments: demo

Upvotes: 1

Related Questions