I would like to add the attribute autoresize=true to a textarea that is drawn using ember-bootstrap in order to use ember-autoresize.
As you can see here, this attribute is not bound, so I cannot simply add it to my template.
I've tried to manipulate the yielded control like so:
{{#bs-form formLayout="vertical" model=email as |form|}}
{{#form.element controlType="textarea" property="textEdit" as |el|}}
{{el.control autoresize=true}}
{{/form.element}}
{{/bs-form}}
But this only works for classNames, not attributes.
What is the simplest way of achieving what I'm trying to do?
There are two ways to do it.
Both examples assume
ember-bootstrapandember-autoresizeare installed.1. Ad-hoc approach: no configuration needed, but less convenient to use
Use "Custom controls" described here.
Here's an example:
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.
Inside that file, do what the autoresize textarea component does, but on top of Ember-Bootstrap's textarea component:
Then you can invoke the Bootstrap textarea component normally:
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: truefrom the component definition. This will let you enable autoresizing individually by passingautoresize=trueinto the{{form.element}}component invocation.