mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat(searchbar): ionChange will only emit from user committed changes (#26026)
This commit is contained in:
18
angular/test/base/e2e/src/searchbar.spec.ts
Normal file
18
angular/test/base/e2e/src/searchbar.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
describe('Searchbar', () => {
|
||||
beforeEach(() => cy.visit('/searchbar'));
|
||||
|
||||
it('should become valid', () => {
|
||||
cy.get('#status').should('have.text', 'INVALID');
|
||||
|
||||
cy.get('ion-searchbar').type('hello');
|
||||
|
||||
cy.get('#status').should('have.text', 'VALID');
|
||||
});
|
||||
|
||||
it('should update the form control value when typing', () => {
|
||||
cy.get('#value').contains(`"searchbar": ""`);
|
||||
cy.get('ion-searchbar').type('hello');
|
||||
|
||||
cy.get('#value').contains(`"searchbar": "hello"`);
|
||||
});
|
||||
});
|
||||
@@ -26,6 +26,7 @@ const routes: Routes = [
|
||||
{ path: 'alerts', component: AlertComponent },
|
||||
{ path: 'inputs', component: InputsComponent },
|
||||
{ path: 'textarea', loadChildren: () => import('./textarea/textarea.module').then(m => m.TextareaModule) },
|
||||
{ path: 'searchbar', loadChildren: () => import('./searchbar/searchbar.module').then(m => m.SearchbarModule) },
|
||||
{ path: 'form', component: FormComponent },
|
||||
{ path: 'modals', component: ModalComponent },
|
||||
{ path: 'modal-inline', loadChildren: () => import('./modal-inline').then(m => m.ModalInlineModule) },
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { NgModule } from "@angular/core";
|
||||
import { RouterModule } from "@angular/router";
|
||||
import { SearchbarComponent } from "./searchbar.component";
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild([
|
||||
{
|
||||
path: '',
|
||||
component: SearchbarComponent
|
||||
}
|
||||
])
|
||||
],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class SearchbarRoutingModule { }
|
||||
16
angular/test/base/src/app/searchbar/searchbar.component.html
Normal file
16
angular/test/base/src/app/searchbar/searchbar.component.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<ion-content>
|
||||
<form [formGroup]="form">
|
||||
<ion-list>
|
||||
<ion-item>
|
||||
<ion-label>Searchbar</ion-label>
|
||||
<ion-searchbar formControlName="searchbar"></ion-searchbar>
|
||||
</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>
|
||||
16
angular/test/base/src/app/searchbar/searchbar.component.ts
Normal file
16
angular/test/base/src/app/searchbar/searchbar.component.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { FormBuilder, Validators } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-searchbar',
|
||||
templateUrl: 'searchbar.component.html',
|
||||
})
|
||||
export class SearchbarComponent {
|
||||
|
||||
form = this.fb.group({
|
||||
searchbar: ['', Validators.required]
|
||||
})
|
||||
|
||||
constructor(private fb: FormBuilder) { }
|
||||
|
||||
}
|
||||
21
angular/test/base/src/app/searchbar/searchbar.module.ts
Normal file
21
angular/test/base/src/app/searchbar/searchbar.module.ts
Normal 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 { SearchbarRoutingModule } from "./searchbar-routing.module";
|
||||
import { SearchbarComponent } from "./searchbar.component";
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
IonicModule,
|
||||
SearchbarRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
SearchbarComponent
|
||||
]
|
||||
})
|
||||
export class SearchbarModule { }
|
||||
Reference in New Issue
Block a user