feat(textarea): ionChange will only emit from user committed changes (#25953)

This commit is contained in:
Sean Perkins
2022-09-23 13:26:21 -04:00
committed by GitHub
parent a03c8afb3d
commit 68bae80a51
15 changed files with 280 additions and 33 deletions

View File

@@ -0,0 +1,18 @@
describe('Textarea', () => {
beforeEach(() => cy.visit('/textarea'));
it('should become valid', () => {
cy.get('#status').should('have.text', 'INVALID');
cy.get('ion-textarea').type('hello');
cy.get('#status').should('have.text', 'VALID');
});
it('should update the form control value when typing', () => {
cy.get('#value').contains(`"textarea": ""`);
cy.get('ion-textarea').type('hello');
cy.get('#value').contains(`"textarea": "hello"`);
});
});

View File

@@ -25,6 +25,7 @@ const routes: Routes = [
{ path: 'accordions', component: AccordionComponent },
{ path: 'alerts', component: AlertComponent },
{ path: 'inputs', component: InputsComponent },
{ path: 'textarea', loadChildren: () => import('./textarea/textarea.module').then(m => m.TextareaModule) },
{ path: 'form', component: FormComponent },
{ path: 'modals', component: ModalComponent },
{ path: 'modal-inline', loadChildren: () => import('./modal-inline').then(m => m.ModalInlineModule) },

View File

@@ -61,7 +61,7 @@
Form Status: <span id="status">{{ profileForm.status }}</span>
</p>
<p>
Form Status: <span id="data">{{ profileForm.value | json }}</span>
Form value: <span id="data">{{ profileForm.value | json }}</span>
</p>
<p>
Form Submit: <span id="submit">{{submitted}}</span>

View File

@@ -0,0 +1,16 @@
import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
import { TextareaComponent } from "./textarea.component";
@NgModule({
imports: [
RouterModule.forChild([
{
path: '',
component: TextareaComponent
}
])
],
exports: [RouterModule]
})
export class TextareaRoutingModule { }

View File

@@ -0,0 +1,16 @@
<ion-content>
<form [formGroup]="form">
<ion-list>
<ion-item>
<ion-label>Textarea</ion-label>
<ion-textarea formControlName="textarea"></ion-textarea>
</ion-item>
</ion-list>
</form>
<p>
Form status: <span id="status">{{ form.status }}</span>
</p>
<p>
Form value: <span id="value">{{ form.value | json }}</span>
</p>
</ion-content>

View File

@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
@Component({
selector: 'app-textarea',
templateUrl: 'textarea.component.html',
})
export class TextareaComponent {
form = this.fb.group({
textarea: ['', Validators.required]
})
constructor(private fb: FormBuilder) { }
}

View File

@@ -0,0 +1,21 @@
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { IonicModule } from "@ionic/angular";
import { TextareaRoutingModule } from "./textarea-routing.module";
import { TextareaComponent } from "./textarea.component";
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
IonicModule,
TextareaRoutingModule
],
declarations: [
TextareaComponent
]
})
export class TextareaModule { }