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

V2.0 blur issue #24

Open
oplahcinski opened this issue Oct 26, 2012 · 1 comment
Open

V2.0 blur issue #24

oplahcinski opened this issue Oct 26, 2012 · 1 comment

Comments

@oplahcinski
Copy link

I found an issue with your blur event.

Using Chrome on Mac, Jquery 1.8.2 and latest 2.0 js as of the date of this posting. Im using an ajax based source not that it matters.

Here is where the issue occurs:

listen: function () {
this.$element
.on('blur', $.proxy(this.blur, this))
.on('keyup', $.proxy(this.keyup, this));

This blur event will sometimes fire and complete before the browser has a chance to send the click event to the typeahead list.

I found changing the timeout from 150ms to 250ms fixed the issue on my development box. Is there a better way we could write this?

@smucode
Copy link
Contributor

smucode commented Nov 17, 2012

This can be fixed by changing the check in the blur function to use hover instead of focus:

blur: function (e) {
    var that = this;
    e.stopPropagation();
    e.preventDefault();
    setTimeout(function () {
        if (!that.$menu.is(':hover')) {
          that.hide();
        }
    }, 150);
},

twbs/bootstrap#2715 (comment)

tgirardi added a commit to tgirardi/twitter-bootstrap-typeahead that referenced this issue Dec 4, 2012
Blur method fires a timeout which will check where the focus is after 150 ms in order to close the menu or keep it open. However, that verification was checking if the $menu was the owner of the focus. $menu is an "ul", so it can't be the owner of any focus. Probably the real intetion was to check $element, so I made the corresponding change.

Note: in issue tcrosen#24 @smucode suggest checking for $menu.is(':hover'). That could be a better solution to the problem discussed in that issue... or probably there's even a better one out there... It would be a good idea to give it some thoughts in order to fix that issue too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants