Skip to content

MdTextareaAutosize: value not rendered with display:none style at initialization of component #3346

Closed

Description

@mitch-berg

Bug, feature request, or proposal:

Bug: When the resizing functionality is used on a textarea within an element whose style contains 'display:none' at initialization the value of the textarea is not rendered to the user. When a user enters the field and begins to provide input the existing data value is then rendered in full.

What is the expected behavior?

Pre-populated data values are displayed to the user when the component becomes visible even if the wrapping container is set to 'display:none' at initialization.

What is the current behavior?

When the container is toggled visible to the user the data value is not displayed. The height of the component appears to be set to 0px by MdTextareaAutosize. Once a user begins to enter more data it triggers another resize and the field populates with the data and resizes.

What are the steps to reproduce?

Plunker template: https://plnkr.co/edit/d6s5aOGvS1ZGLNQR7hSJ?p=preview

This example has two wrapper 'div' elements whose display property is manipulated by a button. One is set to 'display:none' at load and demonstrates the problem of data not being visible when you toggle the 'div' that contains the textarea to be visible.

The second 'div' just demonstrates that the data is present on load as expected when the wrapping 'div' does not have 'display:none' set.

What is the use-case or motivation for changing an existing behavior?

Support pre-populated data in components which require resize on load but may not be visible to users at initialization.

Is there anything else we should know?

Material 1 did some state checking and had a watcher out there that resized when the component became visible based on criteria.

https://github.com/angular/material/blob/v1.1.1/src/components/input/input.js#L604

Activity

  1. added
    feature
    on Mar 1, 2017
  2. rscottfree commented on Mar 6, 2017

    @rscottfree

    Unsurprisingly, this also affects MdTextareaAutosize text areas inside of mdTabs.

    While not ideal, a quick fix to overwrite the height: 0 could be:

    @ViewChild(MdTextareaAutosize, {read: ViewContainerRef})
    myTextArea: ViewContainerRef;
    
    ngAfterViewInit() {
        this.myTextArea.element.nativeElement.style.height = 'auto';
    }
    
  3. programmersharp commented on Apr 27, 2017

    @programmersharp

    I tried this solution but the problem is that when the initial value is multi line, then the default scroll bars appear for textarea.

  4. gedclack commented on Jun 5, 2017

    @gedclack

    +1 👍
    This problem occurs especially when mdTextareaAutosize is present.

  5. jsitu commented on Jul 18, 2017

    @jsitu

    @programmersharp I had the same issue regarding displaying the initial value which is multi-line, did you solve this issue?

  6. programmersharp commented on Jul 19, 2017

    @programmersharp

    @jsitu no, I didn't

  7. jsitu commented on Jul 19, 2017

    @jsitu

    @programmersharp, I found a workaround for the issue:

    this.yourTextArea.nativeElement.style.height 
    = `${this.yourTextArea.nativeElement.scrollHeight}px`;
    

    I have it declared within the ngOnInit lifecycle hook. Kind of hacky but it does the job.

  8. amcdnl commented on Aug 23, 2017

    @amcdnl
    Contributor

    One suggestion might be using *ngIf rather than display: none.

  9. jelbourn commented on Apr 28, 2020

    @jelbourn
    Contributor

    Closing this since I don't think there's a viable way for the directive to know about visibility changes like this.

  10. angular-automatic-lock-bot commented on May 29, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions