Why does core-list doesn't set a height within a core-header-panel?

血红的双手。 提交于 2019-12-10 21:07:15

问题


I've tried to put a <core-list> into a <core-header-panel> but the core-list is not rendered until I give it a height.

So my example code does work with a very silly hack, but I think there must be better way to fit the core-list into the page.

The structure is as follows:

Here's my code:

JSFiddle: http://jsfiddle.net/gu0g8kt3/2/

HTML

<link rel="import" href="http://www.polymer-project.org/components/polymer/polymer.html">
<link rel="import" href="http://www.polymer-project.org/components/paper-elements/paper-elements.html">
<link rel="import" href="http://www.polymer-project.org/components/core-elements/core-elements.html">

<core-drawer-panel>
  <core-header-panel drawer>
    <core-image style="width:256px; height:170px; background-color: lightgray;"
                sizing="cover" preload fade src="http://lorempixel.com/256/170/abstract/"></core-image>

      <core-menu selectedAttribute="">
      <paper-item>
        <core-icon icon="assignment"></core-icon>
        <div>Option #1</div>
      </paper-item>
      <paper-item>
        <core-icon icon="account-circle"></core-icon>
        <div>Option #2</div>
      </paper-item>
    </core-menu>
  </core-header-panel>

  <core-header-panel id="hPanel" main>
    <core-toolbar id="toolbar">
      <paper-menu-button icon="menu" core-drawer-toggle></paper-menu-button>
      <span flex>This is my app!</span>
    </core-toolbar>

    <div class="content">


      <!-- here is the problem -->        
      <core-list id="list" height="120">
        <template>
            <div class="row {{ { selected: selected } | tokenList }}">
                <div flex><core-image style="width:40px; height:40px; background-color: lightgray;" src="{{model.image_src}}" sizing="cover" preload></core-image></div>
            </div>
        </template>
       </core-list>
       <paper-fab class="fab" icon="add"></paper-fab>


    </div>

  </core-header-panel>
</core-drawer-panel>

CSS

core-header-panel {
  background-color: #f9f9f9;
}

.fab {
  position: absolute;
  bottom: 16px;
  right: 16px;
}

/* main area content */
core-list {
  overflow: hidden;
  display: block;
  height: 200px; /* this is just a bad workaround, must be > 0 */
  margin: 0 auto;
}

.row {
  background: lightblue;
  height: 120px;
  overflow: hidden;
  border-bottom: 1px #dedede solid;
}

.selected {
  background: orange;
}

/* drawer content */
core-toolbar {
  color: #2c2c2c;
  letter-spacing: 0.05em;
  text-shadow: 1px 1px 0px #d5d5d5, 2px 2px 0px rgba(0, 0, 0, 0.2);
  text-rendering: optimizeLegibility; }

core-menu {
  margin: 0px;
  margin-top: -4px; }
  core-menu paper-item {
    border-bottom: 1px grey solid; }
    core-menu paper-item > div {
      padding-left: 10px !important; }

JavaScript

var data = [];

for (var i = 0; i < 10000; ++i) {
    data.push({
        image_src: 'http://lorempixel.com/40/40/business/?' + Math.round(Math.random()*100)
    });
}

document.querySelector('#list').data = data;

// the only way it works for me is the following:
var mainPanel = document.querySelector('#hPanel');
var toolbar = document.querySelector('#toolbar');
var list = document.querySelector('#list');

var contentHeight = mainPanel.clientHeight - toolbar.clientHeight;
list.style.height = contentHeight + 'px';

回答1:


As mentioned in this comment, core-list needs some help to be sized properly: https://github.com/Polymer/core-list/issues/47#issuecomment-63126241

I was able to fix your jsfiddle with two changes:

  1. give 'fit' layout to content div, so it will fill entire remaining area in hPanel:
<div class="content" fit>
  1. give 100% height to the list
 <core-list id="list" height="120" style="height:100%;" >

With these changes, setting height for the list in javascript is not necessary.

JSFiddle: http://jsfiddle.net/6ktwg9kk/



来源:https://stackoverflow.com/questions/27251551/why-does-core-list-doesnt-set-a-height-within-a-core-header-panel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!