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

Unified Diff: sky/framework/sky-input.sky

Issue 831353003: Implement <sky-input> (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/examples/widgets/index.sky ('k') | sky/tools/debugger/debugger.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-input.sky
diff --git a/sky/framework/sky-input.sky b/sky/framework/sky-input.sky
new file mode 100644
index 0000000000000000000000000000000000000000..ee790400ae6de56f7465d137ec3a08e412cd82bf
--- /dev/null
+++ b/sky/framework/sky-input.sky
@@ -0,0 +1,51 @@
+<!--
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+-->
+<import src="/sky/framework/sky-element/sky-element.sky" as="SkyElement" />
+
+<sky-element name="sky-input" attributes="value:string">
+<template>
+ <style>
+ :host {
+ display: flex;
+ border: 1px solid blue;
+ margin: 5px;
+ padding: 4px;
+ }
+ #control {
+ align-self: center;
+ height: 1.2em;
+ white-space: nowrap;
+ overflow: hidden;
+ }
+ </style>
+ <div id="control" contenteditable on-keydown="handleKeyDown">{{ value }}</div>
+</template>
+<script>
+module.exports = class extends SkyElement {
+ shadowRootReady() {
+ var control = this.shadowRoot.getElementById('control');
+
+ var observer = new MutationObserver(function() {
+ this.value = control.textContent;
+ this.dispatchEvent(new CustomEvent('change', {
+ bubbles: true,
+ }));
+ }.bind(this));
+
+ observer.observe(control, {
+ subtree: true,
+ characterData: true,
+ childList: true,
+ });
+ }
+ handleKeyDown(event) {
+ // TODO(abarth): You can still get newlines if the user pastes them.
+ if (event.keyCode == 0xD)
+ event.preventDefault();
+ }
+}.register();
+</script>
+</sky-element>
« no previous file with comments | « sky/examples/widgets/index.sky ('k') | sky/tools/debugger/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698