Skip to content

Commit

Permalink
doc(ngx-search-bar): update doc with theming info and fix autocomplet…
Browse files Browse the repository at this point in the history
…e sample
  • Loading branch information
abdes committed Jun 29, 2020
1 parent a9380d4 commit c31073e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions libs/ngx-search-bar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export class AppComponent {
</hc-search-bar>
```

### 4. Include the theming support styles in your app

ngx-search-bar uses SASS styling and provides mixins that can be integrated into
and angular material application theme. Simply follow the instructions for
[Angular Material Theming](https://material.angular.io/guide/theming). The theme
file is located in `node_modules/@npcz/ngx-search-bar/src/styles`.

## Adding search suggestions with autocomplete

The component has zero dependencies on services or providers from the
Expand Down Expand Up @@ -136,11 +143,14 @@ to the search bar and using its observables:
```

```ts
export class GlobalSearchBarComponent extends BaseComponent
implements AfterViewInit {
export class GlobalSearchBarComponent implements AfterViewInit, OnDestroy {
@ViewChild(MatAutocomplete) private _autocomplete: MatAutocomplete;
@ViewChild(SearchBarComponent) private _searchBar: SearchBarComponent;

// Automatic unsubscription when the component is destroyed
// We don't want an emitted value, just the fact of emitting is enough
private _ngUnsubscribe$ = new Subject<never>();

private _searchSuggestions = new BehaviorSubject<string[]>([]);
searchSuggestions: Observable<
string[]
Expand Down Expand Up @@ -179,21 +189,26 @@ export class GlobalSearchBarComponent extends BaseComponent
this._loadSearchSuggestion(value);
}
}),
takeUntil(this.ngUnsubscribe$)
takeUntil(this._ngUnsubscribe$)
)
.subscribe();

// Know when the search needs to be done (user clicked the search button or
// hit the 'Enter' key)
this._searchBar.search
.pipe(takeUntil(this.ngUnsubscribe$))
.pipe(takeUntil(this._ngUnsubscribe$))
.subscribe((value) => {
console.debug('submit: ', value);
// Reset the search suggestions
this._searchSuggestions.next([]);
});
}

ngOnDestroy(): void {
this._ngUnsubscribe$.next();
this._ngUnsubscribe$.complete();
}

// Implementation of the search suggestions.
// Example using goolge search suggestions rest API
private _loadSearchSuggestion(searchOptions): void {
Expand Down

0 comments on commit c31073e

Please sign in to comment.