Skip to content

[Tabs] Textarea values not shown in hidden tabs #5222

Open

Description

@ybeauchamph

Bug, feature request, or proposal:

The value of text area with mdTextareaAutosize is not visible until the size of the text area is recalculated (with resizeToFitContent() or by typing) when the text area is inside an MdTab that is not initially visible.
The min rows is also not working.

What is the expected behavior?

The text area value is visible and min rows works.

What is the current behavior?

The text area value is not visible until the value change by typing or resizeToFitContent is called and min rows doesn't works.

What are the steps to reproduce?

http://plnkr.co/edit/h4EYvCm36ncKlJolJnhU?p=preview
Open plunker and go to the second tab.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 4.2.3
Material: 2.0.0-beta.6
Windows 10
Typescript: 2.3.4

Activity

  1. added
    P2
    help wanted
    on Jun 20, 2017
  2. ybeauchamph commented on Jul 26, 2017

    @ybeauchamph
    Author

    Related to #3346.

  3. amcdnl commented on Aug 23, 2017

    @amcdnl
    Contributor

    @jelbourn - This is likely related to #1854.

    The size of the textarea is calculated on init of the component and the component is not actually injected into the dom until the user clicks the tab.

    Another approach for resolution would be to use the intersection observer to detect when the textarea is in view and then calculate the size. Reference: https://github.com/w3c/IntersectionObserver/blob/gh-pages/explainer.md ... this might be nice CDK directive to have for other situations too.

  4. jelbourn commented on Aug 30, 2017

    @jelbourn
    Contributor

    IntersectionObserver is a long way away from being usable on the platforms we support.

    This is mostly the same as #3346. I don't have any greats ideas for a good way for the autosize to know when it should "go" based on being hidden or not in the DOM. @crisbeto @andrewseguin any thoughts?

  5. crisbeto commented on Aug 30, 2017

    @crisbeto
    Member

    In this case it might be best not to try and handle it automatically, or we risk destroying performance. Instead consumers can get a hold of the MdTextareaAutosize instance and call resizeToFitContent manually when appropriate. Note that we'll probably have to tweak resizeToFitContent since it won't do anything if the value hasn't changed.

  6. jelbourn commented on Aug 30, 2017

    @jelbourn
    Contributor

    We could do something like setting the previous value to '' if the height is zero

  7. MatthewTrout commented on Sep 8, 2017

    @MatthewTrout

    I'd like to be able to get hold of the MdTextareaAutosize instance in order to call resizeToFitContent when appropriate, but I cannot seem to find out how to get a reference to it...

  8. ybeauchamph commented on Sep 8, 2017

    @ybeauchamph
    Author

    @MatthewTrout You can use the ViewChildren decorator.

    In your class properties:
    @ViewChildren(MdTextareaAutosize) textareaAutosizes: QueryList<MdTextareaAutosize>;

    Then you can use it in AfterViewInit:
    this.textareaAutosizes.forEach(autosize => autosize.resizeToFitContent());

  9. amcdnl commented on Sep 9, 2017

    @amcdnl
    Contributor

    @MatthewTrout - You will be able to use the lazy loaded tab feature when it comes out and that should fix this issue.

  10. myrddraall commented on Sep 22, 2017

    @myrddraall

    @Zihark17 this doesn't work due to:

    if (textarea.value === this._previousValue) {
        return;
    }

    at the top of the resizeToFitContent function

    this works but its a nasty workaround:

    this.textareaAutosizes.forEach(autosize => {
        autosize ['_previousValue'] = undefined;
        autosize.resizeToFitContent();
    });
  11. changed the title [-]Value of text area with mdTextareaAutosize is not visible inside MdTab[/-] [+][Tabs] Textarea values not shown in hidden tabs[/+] on Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2area: material/tabshelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions