Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: third_party/polymer/v1_0/components-chromium/iron-list/iron-list.html

Issue 1681053002: Unrestrict version of PolymerElements/iron-list and update it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-closure
Patch Set: and vulcanize Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 @license 2 @license
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt 4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
7 Code distributed by Google as part of the polymer project is also 7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
9 --><html><head><link rel="import" href="../polymer/polymer.html"> 9 --><html><head><link rel="import" href="../polymer/polymer.html">
10 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html "> 10 <link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html ">
11 <link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html ">
12 <link rel="import" href="../iron-scroll-target-behavior/iron-scroll-target-behav ior.html">
11 13
12 <!-- 14 <!--
13 15
14 `iron-list` displays a virtual, 'infinite' list. The template inside 16 `iron-list` displays a virtual, 'infinite' list. The template inside
15 the iron-list element represents the DOM to create for each list item. 17 the iron-list element represents the DOM to create for each list item.
16 The `items` property specifies an array of list item data. 18 The `items` property specifies an array of list item data.
17 19
18 For performance reasons, not every item in the list is rendered at once; 20 For performance reasons, not every item in the list is rendered at once;
19 instead a small subset of actual template elements *(enough to fill the viewport )* 21 instead a small subset of actual template elements *(enough to fill the viewport )*
20 are rendered and reused as the user scrolls. As such, it is important that all 22 are rendered and reused as the user scrolls. As such, it is important that all
21 state of the list template be bound to the model driving it, since the view may 23 state of the list template be bound to the model driving it, since the view may
22 be reused with a new model at any time. Particularly, any state that may change 24 be reused with a new model at any time. Particularly, any state that may change
23 as the result of a user interaction with the list item must be bound to the mode l 25 as the result of a user interaction with the list item must be bound to the mode l
24 to avoid view state inconsistency. 26 to avoid view state inconsistency.
25 27
26 __Important:__ `iron-list` must either be explicitly sized, or delegate scrollin g to an 28 __Important:__ `iron-list` must either be explicitly sized, or delegate scrollin g to an
27 explicitly sized parent. By "explicitly sized", we mean it either has an explici t 29 explicitly sized parent. By "explicitly sized", we mean it either has an explici t
28 CSS `height` property set via a class or inline style, or else is sized by other 30 CSS `height` property set via a class or inline style, or else is sized by other
29 layout means (e.g. the `flex` or `fit` classes). 31 layout means (e.g. the `flex` or `fit` classes).
30 32
31 ### Template model 33 ### Template model
32 34
33 List item templates should bind to template models of the following structure: 35 List item templates should bind to template models of the following structure:
34 36
35 { 37 ```js
36 index: 0, // data index for this item 38 {
37 item: { // user data corresponding to items[index] 39 index: 0, // index in the item array
38 /* user item data */ 40 selected: false, // true if the current item is selected
39 } 41 tabIndex: -1, // a dynamically generated tabIndex for focus management
40 } 42 item: {} // user data corresponding to items[index]
43 }
44 ```
41 45
42 Alternatively, you can change the property name used as data index by changing t he 46 Alternatively, you can change the property name used as data index by changing t he
43 `indexAs` property. The `as` property defines the name of the variable to add to the binding 47 `indexAs` property. The `as` property defines the name of the variable to add to the binding
44 scope for the array. 48 scope for the array.
45 49
46 For example, given the following `data` array: 50 For example, given the following `data` array:
47 51
48 ##### data.json 52 ##### data.json
49 53
50 ```js 54 ```js
51 [ 55 [
52 {"name": "Bob"}, 56 {"name": "Bob"},
53 {"name": "Tim"}, 57 {"name": "Tim"},
54 {"name": "Mike"} 58 {"name": "Mike"}
55 ] 59 ]
56 ``` 60 ```
57 61
58 The following code would render the list (note the name and checked properties a re 62 The following code would render the list (note the name and checked properties a re
59 bound from the model object provided to the template scope): 63 bound from the model object provided to the template scope):
60 64
61 ```html 65 ```html
62 <template is="dom-bind"> 66 <template is="dom-bind">
63 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax> 67 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax>
64 <iron-list items="[[data]]" as="item"> 68 <iron-list items="[[data]]" as="item">
65 <template> 69 <template>
66 <div> 70 <div>
67 Name: <span>[[item.name]]</span> 71 Name: [[item.name]]
68 </div> 72 </div>
69 </template> 73 </template>
70 </iron-list> 74 </iron-list>
71 </template> 75 </template>
72 ``` 76 ```
73 77
78 ### Accessibility
79
80 `iron-list` automatically manages the focus state for the items. It also provide s
81 a `tabIndex` property within the template scope that can be used for keyboard na vigation.
82 For example, users can press the up and down keys to move to previous and next
83 items in the list:
84
85 ```html
86 <iron-list items="[[data]]" as="item">
87 <template>
88 <div tabindex$="[[tabIndex]]">
89 Name: [[item.name]]
90 </div>
91 </template>
92 </iron-list>
93 ```
94
74 ### Styling 95 ### Styling
75 96
76 Use the `--iron-list-items-container` mixin to style the container of items, e.g . 97 You can use the `--iron-list-items-container` mixin to style the container of it ems:
77 98
78 ```css 99 ```css
79 iron-list { 100 iron-list {
80 --iron-list-items-container: { 101 --iron-list-items-container: {
81 margin: auto; 102 margin: auto;
82 }; 103 };
83 } 104 }
84 ``` 105 ```
85 106
86 ### Resizing 107 ### Resizing
87 108
88 `iron-list` lays out the items when it receives a notification via the `iron-res ize` event. 109 `iron-list` lays out the items when it receives a notification via the `iron-res ize` event.
89 This event is fired by any element that implements `IronResizableBehavior`. 110 This event is fired by any element that implements `IronResizableBehavior`.
90 111
91 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t rigger 112 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t rigger
92 this event automatically. If you hide the list manually (e.g. you use `display: none`) 113 this event automatically. If you hide the list manually (e.g. you use `display: none`)
93 you might want to implement `IronResizableBehavior` or fire this event manually right 114 you might want to implement `IronResizableBehavior` or fire this event manually right
94 after the list became visible again. e.g. 115 after the list became visible again. For example:
95 116
96 ```js 117 ```js
97 document.querySelector('iron-list').fire('iron-resize'); 118 document.querySelector('iron-list').fire('iron-resize');
98 ``` 119 ```
99 120
100 ### When should `<iron-list>` be used? 121 ### When should `<iron-list>` be used?
101 122
102 `iron-list` should be used when a page has significantly more DOM nodes than the ones 123 `iron-list` should be used when a page has significantly more DOM nodes than the ones
103 visible on the screen. e.g. the page has 500 nodes, but only 20 are visible at t he time. 124 visible on the screen. e.g. the page has 500 nodes, but only 20 are visible at t he time.
104 This is why we refer to it as a `virtual` list. In this case, a `dom-repeat` wil l still 125 This is why we refer to it as a `virtual` list. In this case, a `dom-repeat` wil l still
105 create 500 nodes which could slow down the web app, but `iron-list` will only cr eate 20. 126 create 500 nodes which could slow down the web app, but `iron-list` will only cr eate 20.
106 127
107 However, having an `iron-list` does not mean that you can load all the data at o nce. 128 However, having an `iron-list` does not mean that you can load all the data at o nce.
108 Say, you have a million records in the database, you want to split the data into pages 129 Say, you have a million records in the database, you want to split the data into pages
109 so you can bring a page at the time. The page could contain 500 items, and iron- list 130 so you can bring a page at the time. The page could contain 500 items, and iron- list
110 will only render 20. 131 will only render 20.
111 132
112 @group Iron Element 133 @group Iron Element
113 @element iron-list 134 @element iron-list
114 @demo demo/index.html Simple list 135 @demo demo/index.html Simple list
115 @demo demo/selection.html Selection of items 136 @demo demo/selection.html Selection of items
116 @demo demo/collapse.html Collapsable items 137 @demo demo/collapse.html Collapsable items
138 @demo demo/scroll-threshold.html Scroll thesholds
139
117 --> 140 -->
118 141
119 </head><body><dom-module id="iron-list"> 142 </head><body><dom-module id="iron-list">
120 <template> 143 <template>
121 <style> 144 <style>
122 :host { 145 :host {
123 display: block; 146 display: block;
124 }
125
126 :host(.has-scroller) {
127 overflow: auto;
128 }
129
130 :host(:not(.has-scroller)) {
131 position: relative; 147 position: relative;
132 } 148 }
133 149
150 @media only screen and (-webkit-max-device-pixel-ratio: 1) {
151 :host {
152 will-change: transform;
153 }
154 }
155
134 #items { 156 #items {
135 @apply(--iron-list-items-container); 157 @apply(--iron-list-items-container);
136 position: relative; 158 position: relative;
137 } 159 }
138 160
139 #items > ::content > * { 161 #items > ::content > * {
140 width: 100%; 162 width: 100%;
141 box-sizing: border-box; 163 box-sizing: border-box;
142 position: absolute; 164 position: absolute;
143 top: 0; 165 top: 0;
144 will-change: transform; 166 will-change: transform;
145 } 167 }
146 </style> 168 </style>
147 169
148 <array-selector id="selector" items="{{items}}" selected="{{selectedItems}}" selected-item="{{selectedItem}}"> 170 <array-selector id="selector" items="{{items}}" selected="{{selectedItems}}" selected-item="{{selectedItem}}">
149 </array-selector> 171 </array-selector>
150 172
151 <div id="items"> 173 <div id="items">
152 <content></content> 174 <content></content>
153 </div> 175 </div>
154 176
155 </template> 177 </template>
156 </dom-module> 178 </dom-module>
157 179
158 <script src="iron-list-extracted.js"></script></body></html> 180 <script src="iron-list-extracted.js"></script></body></html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698