I have implemented a textarea
that grows according to the length. I simply add one to the rows until the scrollHeight
no longer exceeds the clientHeight
.
To avoid the deprecation warnings I put the measurement on the afterRender
queue. It works fine, but when the content grows the rows are increased only after the render and so a scroll bar pops up and disappears (also resetting the cursor to the end of the text).
I have been trying to avoid the flicker of the scrollbar by somehow access the element before it is inserted. The willInsertElement
provides access to element, but it seems to be only called on the first render. What are your thoughts on a work around at the moment?
didReceiveAttrs(){
this.set('model', Object.assign({}, this.get('model'), {
text: this.get('value'),
rows: this.get('min-rows')
}));
Ember.run.scheduleOnce('afterRender', this, 'growRows');
},
growRows() {
const el = this.$('textarea')[0];
const rows = this.get('model.rows');
if(el.scrollHeight > el.clientHeight) {
this.set('model', Object.assign({}, this.get('model'), {
rows: rows + 1
}));
Ember.run.scheduleOnce('afterRender', this, 'growRows');
}
},
callUpdate(val){
this.sendAction('update', val);
Ember.run.scheduleOnce('afterRender', this, 'growRows');
},
actions: {
throttledUpdate(val){
Ember.run.throttle(this, 'callUpdate', val, 200);
}
}
I have also asked this question at the measure hook rfc Add measure hook · Issue #134 · emberjs/rfcs · GitHub