From 2412d6a1f7b59084c756cbc36ce95d7cb4245e8e Mon Sep 17 00:00:00 2001 From: Michael Henkens Date: Wed, 14 Sep 2022 15:35:57 +0200 Subject: [PATCH 1/2] fix(stark-ui): generic-search trigger search on enter When press Enter key now the search is trigger Braking Change: The Components implementing `StarkSearchFormComponent` must implement `submitEvent` In the component template in the
tag `(ngSubmit)="submitEvent.next()" and add `` ISSUES CLOSED: #3116 --- .../generic-search/classes/search-form-component.intf.ts | 5 +++++ .../components/generic-search/generic-search.component.ts | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/stark-ui/src/modules/generic-search/classes/search-form-component.intf.ts b/packages/stark-ui/src/modules/generic-search/classes/search-form-component.intf.ts index 26caa906a7..5867768ca0 100644 --- a/packages/stark-ui/src/modules/generic-search/classes/search-form-component.intf.ts +++ b/packages/stark-ui/src/modules/generic-search/classes/search-form-component.intf.ts @@ -30,4 +30,9 @@ export interface StarkSearchFormComponent { * @param searchCriteria - The search criteria containing the reset values for the form fields */ resetSearchForm(searchCriteria: CriteriaType): void; + + /** + * Emit the submit event when it on enter key + */ + submitEvent: EventEmitter; } diff --git a/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.ts b/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.ts index ac540ea732..1e7342c45c 100644 --- a/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.ts +++ b/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.ts @@ -240,6 +240,9 @@ export class StarkGenericSearchComponent extends AbstractStarkUiComponent implem if (!this.searchFormComponent) { throw new Error("StarkGenericSearchComponent: the searchForm content child is required."); } + this.searchFormComponent.submitEvent.subscribe(() => { + this.triggerSearch(); + }); } /** @@ -536,6 +539,11 @@ export class StarkGenericSearchComponent extends AbstractStarkUiComponent implem } } + public handleKeyUpEnter(event: any): void { + console.log(event); + this.triggerSearch(); + } + /** * Hide the search form and emit a boolean through formVisibilityChanged event emitter that indicates if the search is displayed */ From 16f85f61335c326ec8cd989ced20416bd154d6d0 Mon Sep 17 00:00:00 2001 From: Michael Henkens Date: Thu, 15 Sep 2022 14:11:22 +0200 Subject: [PATCH 2/2] fix(showcase): adapt showcase for the braking change When press Enter key now the search is trigger Braking Change: The Components implementing `StarkSearchFormComponent` must implement `submitEvent` In the component template in the tag `(ngSubmit)="submitEvent.next()" and add `` ISSUES CLOSED: #3116 --- .../generic-search/generic-search.component.spec.ts | 1 + .../components/demo-generic-search-form.component.html | 4 +++- .../components/demo-generic-search-form.component.ts | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.spec.ts b/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.spec.ts index bcbaa030a8..65c5746bb9 100644 --- a/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.spec.ts +++ b/packages/stark-ui/src/modules/generic-search/components/generic-search/generic-search.component.spec.ts @@ -22,6 +22,7 @@ import { StarkActionBarModule } from "../../../action-bar"; }) class TestSearchFormComponent implements StarkSearchFormComponent { public searchForm: FormGroup = new FormGroup({}); + public readonly submitEvent: EventEmitter = new EventEmitter(); public workingCopyChanged = new EventEmitter(); public createSearchForm(_searchCriteria: any): FormGroup { diff --git a/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.html b/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.html index d55b1878e5..b7c4f1d861 100644 --- a/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.html +++ b/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.html @@ -1,4 +1,4 @@ - +
@@ -27,4 +27,6 @@ {{ option }}
+ + diff --git a/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.ts b/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.ts index b45e1dfcd1..b18337244f 100644 --- a/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.ts +++ b/showcase/src/app/demo-ui/pages/generic-search/components/demo-generic-search-form.component.ts @@ -31,6 +31,9 @@ export class DemoGenericSearchFormComponent implements OnInit, StarkSearchFormCo @Output() public readonly workingCopyChanged = new EventEmitter(); + @Output() + public readonly submitEvent: EventEmitter = new EventEmitter(); + public yearOptions: number[] = []; public heroOptions: string[] = []; public movieOptions: string[] = [];