Home | History | Annotate | Download | only in demo
      1 <!doctype html>
      2 <!--
      3 @license
      4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
      5 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
      6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
      7 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
      8 Code distributed by Google as part of the polymer project is also
      9 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
     10 -->
     11 <html>
     12   <head>
     13 
     14     <meta charset="utf-8">
     15     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     16     <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
     17 
     18     <title>iron-autogrow-textarea demo</title>
     19 
     20     <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
     21     <link rel="import" href="../../iron-demo-helpers/demo-snippet.html">
     22     <link rel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html">
     23     <link rel="import" href="../iron-autogrow-textarea.html">
     24 
     25     <style is="custom-style" include="demo-pages-shared-styles">
     26       iron-autogrow-textarea {
     27         display: block;
     28         width: 200px;
     29         margin: 5px 0;
     30       }
     31 
     32       textarea {
     33         width: 200px;
     34       }
     35 
     36       .vertical-section {
     37         box-sizing: border-box;
     38         width: 400px;
     39         margin: 0;
     40       }
     41     </style>
     42   </head>
     43   <body unresolved>
     44     <div class="vertical-section-container centered">
     45       <h3>An iron-autogrow-textarea grows automatically as more text is entered</h3>
     46       <demo-snippet class="centered-demo">
     47         <template>
     48           <iron-autogrow-textarea></iron-autogrow-textarea>
     49         </template>
     50       </demo-snippet>
     51 
     52       <h3>The maximum height can be controlled either through the <i>max-rows</i>
     53       property, or through a fixed max height</h3>
     54       <demo-snippet class="centered-demo">
     55         <template>
     56           <iron-autogrow-textarea max-rows="4" placeholder="scrolls after 4 rows"></iron-autogrow-textarea>
     57           <iron-autogrow-textarea style="max-height: 50px;" placeholder="scrolls after 50px"></iron-autogrow-textarea>
     58         </template>
     59       </demo-snippet>
     60 
     61       <h3>The initial height can also be controlled using the <i>rows</i> property,
     62       or through a fixed height</h3>
     63       <demo-snippet class="centered-demo">
     64         <template>
     65           <iron-autogrow-textarea rows="4" placeholder="start with 4 rows"></iron-autogrow-textarea>
     66           <iron-autogrow-textarea style="height: 50px;"></iron-autogrow-textarea>
     67         </template>
     68       </demo-snippet>
     69 
     70       <h3>Example of updating the value imperatively</h3>
     71       <!-- TODO: replace this with a demo-snippet when https://github.com/webcomponents/webcomponentsjs/issues/362
     72       is fixed -->
     73       <div class="example">
     74         <template is="dom-bind">
     75           <div class="vertical-section">
     76             <iron-autogrow-textarea bind-value="{{bindValue}}" id="a1"></iron-autogrow-textarea>
     77             <br>
     78             <code>bind-value</code>: <span>[[bindValue]]</span>
     79             <p on-click="setValue">
     80               Imperatively changing <code>bind-value</code> will also update
     81               <code>textarea.value</code>:<br>
     82               <textarea></textarea>
     83               <button value="bindValue">set</button>
     84               <br><br>
     85 
     86               Imperatively updating <code>textarea.value</code> will update
     87               the display, but not update <code>bind-value</code>:<br>
     88               <textarea></textarea>
     89               <button value="value">set</button>
     90             </p>
     91           </div>
     92         </template>
     93       </div>
     94     </div>
     95     <script>
     96       var scope = document.querySelector('template[is=dom-bind]');
     97 
     98       scope.setValue = function(event) {
     99         if (!(event.target instanceof HTMLButtonElement)) {
    100           return;
    101         }
    102         var inputValue = event.target.previousElementSibling.value;
    103         if (event.target.value == "bindValue") {
    104           document.querySelector('#a1').bindValue = inputValue;
    105         } else {
    106           document.querySelector('#a1').textarea.value = inputValue;
    107         }
    108       }
    109     </script>
    110   </body>
    111 </html>
    112