Skip to content

ion-label does not float properly with ion-textarea #17555

Closed

Description

@rianne-pagtalunan

Bug Report

Ionic version:
[x] 4.x

Current behavior:
When a default value is present for an ion-textarea, the ion-label does not float properly. Ion-item css styles shows the css class item-input instead of item-has-value. This behavior is observed using latest beta.16 of ionic/angular
image

The behavior corrects when focus has been applied to the ion-textarea.
image

Expected behavior:
When an ion-textarea has a value, the label should float properly.

Steps to reproduce:

Related code:

<ion-list inset>
            <ion-item no-padding>
                <ion-label position="floating">Status</ion-label>
                <ion-select formControlName="status">
                    <ion-select-option value="New">New</ion-select-option>
                    <ion-select-option value="Processing">Processing</ion-select-option>
                    <ion-select-option value="Accepted">Accepted</ion-select-option>
                    <ion-select-option value="Rejected">Rejected</ion-select-option>
                    <ion-select-option value="Cancelled">Cancelled</ion-select-option>
                </ion-select>
            </ion-item>
            <ion-item no-padding>
                <ion-label position="floating">Incident Date</ion-label>
                <ion-datetime formControlName="incidentDate" displayFormat="DD MMM YYYY"></ion-datetime>
            </ion-item>
            <ion-item no-padding>
                <ion-label position="floating">Description</ion-label>
                <ion-textarea formControlName="description" type="text" rows="5" required="true"></ion-textarea>
            </ion-item>
</ion-list>

Other information:

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.4.0
   Ionic Framework               : @ionic/angular 4.0.0-beta.16
   @angular-devkit/build-angular : 0.12.3
   @angular-devkit/schematics    : 7.0.7
   @angular/cli                  : 7.0.7
   @ionic/angular-toolkit        : 1.2.0

System:

   NodeJS : v8.12.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

Activity

  1. akki-jat commented on Mar 2, 2019

    @akki-jat

    Hi @rianne-pagtalunan, facing the same problem. Got any solution?

  2. rianne-pagtalunan commented on Mar 4, 2019

    @rianne-pagtalunan
    Author

    hi @akki-jat, still nothing. I've switched to using fixed/stacked labels when text-area has a value as a temporary workaround.

  3. akki-jat commented on Mar 7, 2019

    @akki-jat

    @rianne-pagtalunan I am using a hack. Just disable then set value and enable the textarea JS/TS code.

  4. MaxiAringoli commented on Mar 27, 2019

    @MaxiAringoli

    Same problem

  5. added
    package: core
    type: bug
    on Apr 11, 2019
  6. brandyscarney commented on Apr 11, 2019

    @brandyscarney
    Member

    Thanks for the issue! I believe this is related to Angular forms. Could you test to see if it works setting the value with ngModel?

  7. mburger81 commented on Apr 12, 2019

    @mburger81
    Contributor

    We did this

    <ion-list>
        <ion-item>
            <ion-label position="floating">Test 1</ion-label>
            <ion-textarea clearInput></ion-textarea>
        </ion-item>
        <ion-item>
            <ion-label position="floating">Test 2</ion-label>
            <ion-textarea clearInput value="YES"></ion-textarea>
        </ion-item>
        <ion-item>
            <ion-label position="floating">Test 3</ion-label>
            <ion-textarea clearInput [value]="angular"></ion-textarea>
        </ion-item>
        <ion-item>
            <ion-label position="floating">Test 4</ion-label>
            <ion-textarea clearInput [value]="angularAsync"></ion-textarea>
        </ion-item>
        <ion-item>
            <ion-label position="floating">Test 5</ion-label>
            <ion-textarea clearInput [(ngModel)]="angularNgModel"></ion-textarea>
        </ion-item>
        <ion-item>
            <ion-label position="floating">Test 6</ion-label>
            <ion-textarea clearInput [(ngModel)]="angularAsyncNgModel"></ion-textarea>
        </ion-item>
    </ion-list>
    

    And this is the result:
    image

    As you can see if using angular or ngmodel binding which is async the floating label is not working. All the other use cases are working

  8. brandyscarney commented on Apr 12, 2019

    @brandyscarney
    Member

    Thanks so much @mburger81! That helps a lot. I confirmed that this happens to textarea with a setTimeout on it in core, without Angular. It does not happen to the ion-input. Here's a Codepen reproducing it: https://codepen.io/brandyscarney/pen/XQgwJM

    I'll add it to the project. I think the problem is as simple as this.emitStyle() not being called on value change:

      @Watch('value')
      protected valueChanged() {
        const nativeInput = this.nativeInput;
        const value = this.getValue();
        if (nativeInput && nativeInput.value !== value) {
          nativeInput.value = value;
        }
        this.ionChange.emit({ value });
      }
    

    I'll take a quick look at this.

  9. added a commit that references this issue on Apr 12, 2019
    94dc405
  10. brandyscarney commented on Apr 12, 2019

    @brandyscarney
    Member

    That was definitely the problem, submitted a pull request with the fix: #18024

  11. added a commit that references this issue on Apr 12, 2019
    494991e
  12. mburger81 commented on Apr 18, 2019

    @mburger81
    Contributor

    version 4.3.0 definitely resolves the issue for us

  13. ionitron-bot commented on May 18, 2019

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  14. locked and limited conversation to collaborators on May 18, 2019
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

    package: angularpackage: coretype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions