Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stark-ui): generic-search trigger search on enter #3459

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ export interface StarkSearchFormComponent<CriteriaType> {
* @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<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { StarkActionBarModule } from "../../../action-bar";
})
class TestSearchFormComponent implements StarkSearchFormComponent<any> {
public searchForm: FormGroup = new FormGroup({});
public readonly submitEvent: EventEmitter<void> = new EventEmitter<void>();
public workingCopyChanged = new EventEmitter<any>();

public createSearchForm(_searchCriteria: any): FormGroup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form fxLayout="row wrap" [formGroup]="searchForm">
<form fxLayout="row wrap" [formGroup]="searchForm" (ngSubmit)="submitEvent.next()">
<!-- Year -->
<div fxFlex>
<mat-form-field>
Expand Down Expand Up @@ -27,4 +27,6 @@
<mat-option *ngFor="let option of movieOptions; trackBy: trackItemFn" [value]="option">{{ option }}</mat-option>
</mat-autocomplete>
</div>

<button [hidden]="true" type="submit">&nbsp;</button>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class DemoGenericSearchFormComponent implements OnInit, StarkSearchFormCo
@Output()
public readonly workingCopyChanged = new EventEmitter<HeroMovieSearchCriteria>();

@Output()
public readonly submitEvent: EventEmitter<void> = new EventEmitter<void>();

public yearOptions: number[] = [];
public heroOptions: string[] = [];
public movieOptions: string[] = [];
Expand Down