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.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/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 */ 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[] = [];