OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. |
| 5 --> |
| 6 <import src="/sky/framework/sky-element/sky-element.sky" as="SkyElement" /> |
| 7 |
| 8 <sky-element name="sky-input" attributes="value:string"> |
| 9 <template> |
| 10 <style> |
| 11 :host { |
| 12 display: flex; |
| 13 border: 1px solid blue; |
| 14 margin: 5px; |
| 15 padding: 4px; |
| 16 } |
| 17 #control { |
| 18 align-self: center; |
| 19 height: 1.2em; |
| 20 white-space: nowrap; |
| 21 overflow: hidden; |
| 22 } |
| 23 </style> |
| 24 <div id="control" contenteditable on-keydown="handleKeyDown">{{ value }}</div> |
| 25 </template> |
| 26 <script> |
| 27 module.exports = class extends SkyElement { |
| 28 shadowRootReady() { |
| 29 var control = this.shadowRoot.getElementById('control'); |
| 30 |
| 31 var observer = new MutationObserver(function() { |
| 32 this.value = control.textContent; |
| 33 this.dispatchEvent(new CustomEvent('change', { |
| 34 bubbles: true, |
| 35 })); |
| 36 }.bind(this)); |
| 37 |
| 38 observer.observe(control, { |
| 39 subtree: true, |
| 40 characterData: true, |
| 41 childList: true, |
| 42 }); |
| 43 } |
| 44 handleKeyDown(event) { |
| 45 // TODO(abarth): You can still get newlines if the user pastes them. |
| 46 if (event.keyCode == 0xD) |
| 47 event.preventDefault(); |
| 48 } |
| 49 }.register(); |
| 50 </script> |
| 51 </sky-element> |
OLD | NEW |