question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typeahead has document click handler even when autocomplete not in use

See original GitHub issue

Bug description:

For every typeahead you have on a page, there is a document click handler which handles dismissing a popup. This event is always bound regardless of if the input has focus, or a typeahead popup is open.

This means every time a user clicks a page, the dismissPopup function is going to run for each typeahead on the screen.

We could change to something like this which we subscribe/unsubscribe to when needed.

private documentClickObservable = Observable.fromEvent(document, 'click');
private documentClickSubscription: Subscription;

When you subscribe to the observable, the callback will fire only until you unsubscribe, in which case it will lie dormant.

We could subscribe when a popup is opened, and unsubscribe when it is closed.

I can put out a PR for this, I wanted to hear people’s thoughts first.

Link to minimally-working plunker that reproduces the issue:

This can be found by putting a breakpoint in the dismissPopup function in the demo, and clicking around on the page.

Version of Angular, ng-bootstrap, and Bootstrap:

Angular: 4.0.1

ng-bootstrap: 1.0.0-alpha.22

Bootstrap: 4.0.0-alpha.6

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
wesleychocommented, Apr 22, 2017

IMO the first solution is much better - it avoids being opinionated by introducing HTML/CSS into the mix, would could lead to problems if users have particular UX needs.

I think that Angular should provide this feature in core itself (https://github.com/angular/angular/issues/15905), but I don’t think we can wait for Angular to implement this - it may be better for us to implement a version specific to our purposes and remove it in favor of Angular’s version down the line.

0reactions
wKozacommented, May 6, 2017

So @wesleycho , @pkozlowski-opensource , what can we do ?

  • subscribe / unsubscribe , for each widget, on the open / close state with a code like this :
private _openPopup() { 
this.removeListenerClickonDocument = this._renderer.listen('document', 'click', this.dismissPopup.bind(this)); 
}

 private _closePopup() {
this.removeListenerClickonDocument();
}
  • Create a service for this (but I’m confused about using the Renderer in a service.

?

Read more comments on GitHub >

github_iconTop Results From Across the Web

typeahead.js autocomplete is not showing any suggestions ...
This is my cshtml file and I'm using typeahead in script to load and autocomplete my text-box while entering the customer name. I...
Read more >
jQuery | Autocomplete Selection Event - GeeksforGeeks
The autocomplete select action is triggered when the user selects one of the options from the pre-populated list. The very common universal ...
Read more >
jQuery Typeahead Search Configuration - RunningCoder
Configure jQuery Typeahead Search plugin, learn about the options and what they can do to improve your search bar.
Read more >
How to implement autocomplete with JavaScript on your website
Adding a query suggestions database. This code has the same finite dataset of terms we used previously. We're still prototyping. You'll need to ......
Read more >
AutoCompleteTextView - Android Developers
android:clickable, Defines whether this view reacts to click events. ... Returns the id for the view that the auto-complete drop down list is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found