Skip to content

Instantly share code, notes, and snippets.

@nishanmiranda
Created May 5, 2016 17:23
Show Gist options
  • Save nishanmiranda/9b022e0e9790bb7fdfe0a49e9bf1be2b to your computer and use it in GitHub Desktop.
Save nishanmiranda/9b022e0e9790bb7fdfe0a49e9bf1be2b to your computer and use it in GitHub Desktop.
autoexpand-textarea
import Ember from 'ember';
export default Ember.TextArea.extend({
rows: 2,
keyDown(ev) {
let keyCode = ev.keyCode;
if (keyCode === 8 || keyCode === 45) {
this.$().attr('rows', 2);
}
},
didInsertElement() {
this._super(...arguments);
let $this = this.$();
let rows = this.get('rows') || '2';
this.initialPaddingTop = parseInt($this.css('padding-top'), 10);
this.initialPaddingBottom = parseInt($this.css('padding-bottom'), 10);
this.initialHeightPerRow = ( this.element.clientHeight - this.initialPaddingTop - this.initialPaddingBottom ) / Number(rows);
this.input();
},
input() {
let rows = ((this.element.scrollHeight - this.initialPaddingTop - this.initialPaddingBottom) / this.initialHeightPerRow).toFixed(0);
this.$().attr('rows', rows);
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component value=value}}
{{outlet}}
<br>
<br>
{
"version": "0.8.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment