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
add an observable for isPopupOpen for ngb-typeahead #3078
Comments
Even more powerful option would be to expose the currently shown options: /// class NgbTypeahead
optionsShown:Observable<Array> | null; //null indicates that the the typeahead window is not opened. If the typeahead is opened, we will see an array of the currently shown options. this way the user will be able to subscribe to the stream of arrays like so: /// my component
class MyComponent {
@ViewChild(NgbTypeahead) ngbTypeahead: NgbTypeahead;
ngAfterViewInit() {
this.ngbTypeahead.optionsShown.subscribe(optionsShown => {
if (optionsShown===null) console.log('the options window is now closed')
else console.log('currently shown options:', optionShown)
})
} |
To have the list of options show one can pipe into suggestions observable. <input type="text" [ngbTypeahead]="find" /> find = this.fetchDataFromBackEnd()
.pipe(tap(results => this.showedOptions = results))
.subscribe(); My mind can not come up with a nice scenario when @ganqqwerty if you can provide justification for this feature, I suppose for the rulers of ng-bootstrap it would be easy to decide if it needed to add this feature into the code base. |
@IAfanasov I believe this feature will improve the customizability of the typeahead component. In particular I'm working on this UI, and I would find this feature super useful to style my component accordingly (when the typeahead is opened / closed). Based on your suggestion, currently I'm using an RxJs subject that taps on the search Observable and emits Having an observable to hold the state of the popup would be a cleaner solution IMO. @maxokorokov, @pkozlowski-opensource would you consider approving this feature request? |
this would be a very helpful feature, especially if we want to customize typeahead window in case no results come from api or so; for example display no results found to the user |
NgTypeahead has a method
isPopupOpen(): boolean
that allows us to understand if the typeahead popup is open.The problem with this method is that it's synchronous. In some cases we want to react on the popup being opened or closed.
For that I suggest to implement an observable that will hold the state of the popup like so:
this way the user will be able to subscribe to the stream of booleans like so:
The text was updated successfully, but these errors were encountered: