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

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

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 <!--- 2 <!---
3 3
4 This README is automatically generated from the comments in these files: 4 This README is automatically generated from the comments in these files:
5 iron-list.html 5 iron-list.html
6 6
7 Edit those files, and our readme bot will duplicate them over here! 7 Edit those files, and our readme bot will duplicate them over here!
8 Edit this file, and the bot will squash your changes :) 8 Edit this file, and the bot will squash your changes :)
9 9
10 The bot does some handling of markdown. Please file a bug if it does the wrong
11 thing! https://github.com/PolymerLabs/tedium/issues
12
10 --> 13 -->
11 14
12 [![Build Status](https://travis-ci.org/PolymerElements/iron-list.svg?branch=mast er)](https://travis-ci.org/PolymerElements/iron-list) 15 [![Build Status](https://travis-ci.org/PolymerElements/iron-list.svg?branch=mast er)](https://travis-ci.org/PolymerElements/iron-list)
13 16
14 _[Demo and API Docs](https://elements.polymer-project.org/elements/iron-list)_ 17 _[Demo and API Docs](https://elements.polymer-project.org/elements/iron-list)_
15 18
16 19
17 ##&lt;iron-list&gt; 20 ##&lt;iron-list&gt;
18 21
19
20
21 `iron-list` displays a virtual, 'infinite' list. The template inside 22 `iron-list` displays a virtual, 'infinite' list. The template inside
22 the iron-list element represents the DOM to create for each list item. 23 the iron-list element represents the DOM to create for each list item.
23 The `items` property specifies an array of list item data. 24 The `items` property specifies an array of list item data.
24 25
25 For performance reasons, not every item in the list is rendered at once; 26 For performance reasons, not every item in the list is rendered at once;
26 instead a small subset of actual template elements *(enough to fill the viewport )* 27 instead a small subset of actual template elements *(enough to fill the viewport )*
27 are rendered and reused as the user scrolls. As such, it is important that all 28 are rendered and reused as the user scrolls. As such, it is important that all
28 state of the list template be bound to the model driving it, since the view may 29 state of the list template be bound to the model driving it, since the view may
29 be reused with a new model at any time. Particularly, any state that may change 30 be reused with a new model at any time. Particularly, any state that may change
30 as the result of a user interaction with the list item must be bound to the mode l 31 as the result of a user interaction with the list item must be bound to the mode l
31 to avoid view state inconsistency. 32 to avoid view state inconsistency.
32 33
33 __Important:__ `iron-list` must either be explicitly sized, or delegate scrollin g to an 34 __Important:__ `iron-list` must either be explicitly sized, or delegate scrollin g to an
34 explicitly sized parent. By "explicitly sized", we mean it either has an explici t 35 explicitly sized parent. By "explicitly sized", we mean it either has an explici t
35 CSS `height` property set via a class or inline style, or else is sized by other 36 CSS `height` property set via a class or inline style, or else is sized by other
36 layout means (e.g. the `flex` or `fit` classes). 37 layout means (e.g. the `flex` or `fit` classes).
37 38
38 ### Template model 39 ### Template model
39 40
40 List item templates should bind to template models of the following structure: 41 List item templates should bind to template models of the following structure:
41 42
42 { 43 ```js
43 index: 0, // data index for this item 44 {
44 item: { // user data corresponding to items[index] 45 index: 0, // index in the item array
45 /* user item data */ 46 selected: false, // true if the current item is selected
46 } 47 tabIndex: -1, // a dynamically generated tabIndex for focus management
47 } 48 item: {} // user data corresponding to items[index]
49 }
50 ```
48 51
49 Alternatively, you can change the property name used as data index by changing t he 52 Alternatively, you can change the property name used as data index by changing t he
50 `indexAs` property. The `as` property defines the name of the variable to add to the binding 53 `indexAs` property. The `as` property defines the name of the variable to add to the binding
51 scope for the array. 54 scope for the array.
52 55
53 For example, given the following `data` array: 56 For example, given the following `data` array:
54 57
55 ##### data.json 58 ##### data.json
56 59
57 ```js 60 ```js
58 [ 61 [
59 {"name": "Bob"}, 62 {"name": "Bob"},
60 {"name": "Tim"}, 63 {"name": "Tim"},
61 {"name": "Mike"} 64 {"name": "Mike"}
62 ] 65 ]
63 ``` 66 ```
64 67
65 The following code would render the list (note the name and checked properties a re 68 The following code would render the list (note the name and checked properties a re
66 bound from the model object provided to the template scope): 69 bound from the model object provided to the template scope):
67 70
68 ```html 71 ```html
69 <template is="dom-bind"> 72 <template is="dom-bind">
70 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax> 73 <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax>
71 <iron-list items="[[data]]" as="item"> 74 <iron-list items="[[data]]" as="item">
72 <template> 75 <template>
73 <div> 76 <div>
74 Name: <span>[[item.name]]</span> 77 Name: [[item.name]]
75 </div> 78 </div>
76 </template> 79 </template>
77 </iron-list> 80 </iron-list>
78 </template> 81 </template>
79 ``` 82 ```
80 83
84 ### Accessibility
85
86 `iron-list` automatically manages the focus state for the items. It also provide s
87 a `tabIndex` property within the template scope that can be used for keyboard na vigation.
88 For example, users can press the up and down keys to move to previous and next
89 items in the list:
90
91 ```html
92 <iron-list items="[[data]]" as="item">
93 <template>
94 <div tabindex$="[[tabIndex]]">
95 Name: [[item.name]]
96 </div>
97 </template>
98 </iron-list>
99 ```
100
81 ### Styling 101 ### Styling
82 102
83 Use the `--iron-list-items-container` mixin to style the container of items, e.g . 103 You can use the `--iron-list-items-container` mixin to style the container of it ems:
84 104
85 ```css 105 ```css
86 iron-list { 106 iron-list {
87 --iron-list-items-container: { 107 --iron-list-items-container: {
88 margin: auto; 108 margin: auto;
89 }; 109 };
90 } 110 }
91 ``` 111 ```
92 112
93 ### Resizing 113 ### Resizing
94 114
95 `iron-list` lays out the items when it receives a notification via the `iron-res ize` event. 115 `iron-list` lays out the items when it receives a notification via the `iron-res ize` event.
96 This event is fired by any element that implements `IronResizableBehavior`. 116 This event is fired by any element that implements `IronResizableBehavior`.
97 117
98 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t rigger 118 By default, elements such as `iron-pages`, `paper-tabs` or `paper-dialog` will t rigger
99 this event automatically. If you hide the list manually (e.g. you use `display: none`) 119 this event automatically. If you hide the list manually (e.g. you use `display: none`)
100 you might want to implement `IronResizableBehavior` or fire this event manually right 120 you might want to implement `IronResizableBehavior` or fire this event manually right
101 after the list became visible again. e.g. 121 after the list became visible again. For example:
102 122
103 ```js 123 ```js
104 document.querySelector('iron-list').fire('iron-resize'); 124 document.querySelector('iron-list').fire('iron-resize');
105 ``` 125 ```
106 126
107 ### When should `<iron-list>` be used? 127 ### When should `<iron-list>` be used?
108 128
109 `iron-list` should be used when a page has significantly more DOM nodes than the ones 129 `iron-list` should be used when a page has significantly more DOM nodes than the ones
110 visible on the screen. e.g. the page has 500 nodes, but only 20 are visible at t he time. 130 visible on the screen. e.g. the page has 500 nodes, but only 20 are visible at t he time.
111 This is why we refer to it as a `virtual` list. In this case, a `dom-repeat` wil l still 131 This is why we refer to it as a `virtual` list. In this case, a `dom-repeat` wil l still
112 create 500 nodes which could slow down the web app, but `iron-list` will only cr eate 20. 132 create 500 nodes which could slow down the web app, but `iron-list` will only cr eate 20.
113 133
114 However, having an `iron-list` does not mean that you can load all the data at o nce. 134 However, having an `iron-list` does not mean that you can load all the data at o nce.
115 Say, you have a million records in the database, you want to split the data into pages 135 Say, you have a million records in the database, you want to split the data into pages
116 so you can bring a page at the time. The page could contain 500 items, and iron- list 136 so you can bring a page at the time. The page could contain 500 items, and iron- list
117 will only render 20. 137 will only render 20.
118 138
119 139
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698