Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

Paper autogrow text area does not grow when calling update() #79

Closed
alextekartik opened this issue Jan 5, 2015 · 3 comments · Fixed by #92 · May be fixed by googlearchive/paper-input#133
Closed

Paper autogrow text area does not grow when calling update() #79

alextekartik opened this issue Jan 5, 2015 · 3 comments · Fixed by #92 · May be fixed by googlearchive/paper-input#133

Comments

@alextekartik
Copy link

According to Polymer documentation (https://www.polymer-project.org/docs/elements/paper-elements.html#paper-autogrow-textarea), doing the following code should resize the text-area

t1.value = 'some\ntext';
a1.update();

I made a simple example and the textarea does not grow when update() is called, it only grows when I start typing in the area. I created a sample project here: https://github.com/alextekartik/dart-test/tree/master/paper_autogrow_textarea_test
with the following html file that shows the issue:

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>paper_autogrow_textarea_test</title>
    <link rel="import" href="packages/paper_elements/paper_autogrow_textarea.html">
    <link rel="import" href="packages/paper_elements/paper_input_decorator.html">
  </head>

  <body unresolved>
    <paper-input-decorator label="with autogrowing text area">
      <paper-autogrow-textarea id="simple_autogrow_textarea">
        <textarea id="simple_textarea"></textarea>
      </paper-autogrow-textarea>
    </paper-input-decorator>   
    <script type="application/dart">
      import 'package:polymer/polymer.dart';
      import 'package:paper_elements/paper_input_decorator.dart';
      import 'package:paper_elements/paper_autogrow_textarea.dart';
      import 'dart:html';

      main() {
        initPolymer().run(() {
          Polymer.onReady.then((_) {
            (querySelector('#simple_textarea') as TextAreaElement).value = "Some\nmulti-line\ntext";
            (querySelector('#simple_autogrow_textarea') as PaperAutogrowTextarea).update();
          });
        });
      }
    </script>
  </body>
</html>

Is there any workaround? The issue is that in a form where I want to allow updating a multiline text, the initial text is never display correctly in the textarea (only the first line is displayed - yes I can play with the rows attribute but in this case if I put too many rows, it does not shrink properly neither)

@jakemac53
Copy link
Contributor

It looks like you have to pass the textarea element to the update() function, so the comment needs to be updated. Also our wrappers either didn't pick up the argument or it wasn't properly commented in the previous version so you will have to use js-interop directly for now, this can be done by changing your code inside onReady to the following:

var t = (querySelector('#simple_textarea') as TextAreaElement);
t.value = "Some\nmulti-line\ntext";
(querySelector('#simple_autogrow_textarea') as PaperAutogrowTextarea).jsElement.callMethod('update', [t]);

It shouldn't be necessary for you to pass this argument at all, I am going to work on a pull request to clean this up on the js side as there are a few wonky things I see (such as an unused target published attribute which would be useful here).

@alextekartik
Copy link
Author

Thanks for the workaround which works great (and indeed I looked at the js code which does require an input parameter for the update method while the documentation states it does not)

@sigmundch
Copy link
Contributor

Jake - it seems like the signature of our element is missing the argument. I wonder if we should update the autogenerated class in the meantime while we wait for your change to get merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
3 participants