如何在dart中自动生成textarea元素?

Kas*_*per 3 dart

我想要一个textarea元素,动态调整其高度为textarea元素的内容.

我怎么能在Dart中实现这个?

Kas*_*per 6

只使用纯粹的飞镖:html:

var textArea = querySelector('textarea');
textArea.onInput.listen((_) {
  // shrink the textarea when needed
  textArea.style.height = 'auto';

  // set the height to scrollHeight plus some correction
  var correction = textArea.offsetHeight - textArea.clientHeight;
  textArea.style.height = '${textArea.scrollHeight - correction}px';
});
Run Code Online (Sandbox Code Playgroud)

你也可以制作一个angular2指令:

@Directive(
    selector: 'textarea[autogrow]',
    host: const {
      '(input)': 'onInput(\$event.target)'
    }
)
class AutogrowDirective {

  onInput(TextAreaElement textArea) {
    // shrink the textarea when needed
    textArea.style.height = 'auto';

    // set the height to scrollHeight plus some correction
    var correction = textArea.offsetHeight - textArea.clientHeight;
    textArea.style.height = '${textArea.scrollHeight - correction}px';
  }
}
Run Code Online (Sandbox Code Playgroud)