There are two ways to do it.
Both examples assume ember-bootstrap
and ember-autoresize
are installed.
1. Ad-hoc approach: no configuration needed, but less convenient to use
Use "Custom controls" described here.
Here's an example:
{{#bs-form formLayout="vertical" model=email as |form|}}
{{#form.element controlType="textarea" property="textEdit" as |el|}}
{{textarea autoresize=true id=el.id value=el.value class="form-control"}}
{{/form.element}}
{{/bs-form}}
Demo: https://ember-twiddle.com/4860f5d660dceadc804495d2720f69f6?openFiles=templates.application.hbs%2C
2. Robust approach: configuration needed, but more convenient to use
Override the original textarea component.
Here's the path for the Classic project structure. For Pods or Module Unification, the path will be different.
app/components/bs-form/element/control/textarea.js
Inside that file, do what the autoresize textarea component does, but on top of Ember-Bootstrap's textarea component:
import BootstrapTextareaComponent from 'ember-bootstrap/components/bs-form/element/control/textarea';
import AutoResizeMixin from 'ember-autoresize/mixins/autoresize';
import { computed, get } from '@ember/object';
import { isEmpty, isNone } from '@ember/utils';
export default BootstrapTextareaComponent.extend(AutoResizeMixin, {
autoresize: true,
shouldResizeHeight: true,
significantWhitespace: true,
autoResizeText: computed('value', 'placeholder', {
get() {
var placeholder = get(this, 'placeholder');
var value = get(this, 'value');
var fillChar = '@';
if (isEmpty(value)) {
return isEmpty(placeholder) ? fillChar : placeholder + fillChar;
}
if (isNone(value)) {
value = '';
}
return value + fillChar;
}
})
});
Then you can invoke the Bootstrap textarea component normally:
{{#bs-form model=this formLayout="vertical" as |form|}}
{{form.element label="Inline" placeholder="Enter description..." property="appName" controlType="textarea"}}
{{/bs-form}}
Demo: https://ember-twiddle.com/693209c5fd4c2eeae765827f42dbd635?openFiles=templates.application.hbs%2C
The above code will enable autoresizing to all Ember-Bootstrap textareas. If you need granular control, you can also remove autoresize: true
from the component definition. This will let you enable autoresizing individually by passing autoresize=true
into the {{form.element}}
component invocation.