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

Prevent clicks on scroll bar from closing dropdown in ie #752

Merged
merged 1 commit into from
Mar 8, 2014
Merged
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
36 changes: 23 additions & 13 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ var Typeahead = (function() {
$input = this.$node.find('.tt-input');
$hint = this.$node.find('.tt-hint');

// #705: if there's scrollable overflow, ie doesn't support
// blur cancellations when the scrollbar is clicked
//
// #351: preventDefault won't cancel blurs in ie <= 8
$input.on('blur.tt', function($e) {
var active, isActive, hasActive;

active = document.activeElement;
isActive = $menu.is(active);
hasActive = $menu.has(active).length > 0;

if (_.isMsie() && (isActive || hasActive)) {
$e.preventDefault();
// stop immediate in order to prevent Input#_onBlur from
// getting exectued
$e.stopImmediatePropagation();
_.defer(function() { $input.focus(); });
}
});

// #351: prevents input blur due to clicks within dropdown menu
$menu.on('mousedown.tt', function($e) { $e.preventDefault(); });

this.eventBus = o.eventBus || new EventBus({ el: $input });

this.dropdown = new Dropdown({ menu: $menu, datasets: o.datasets })
Expand All @@ -50,19 +73,6 @@ var Typeahead = (function() {
.onSync('rightKeyed', this._onRightKeyed, this)
.onSync('queryChanged', this._onQueryChanged, this)
.onSync('whitespaceChanged', this._onWhitespaceChanged, this);

// #351: prevents input blur on menu click
$menu.on('mousedown.tt', function($e) {
if (_.isMsie() && _.isMsie() < 9) {
$input[0].onbeforedeactivate = function() {
window.event.returnValue = false;
$input[0].onbeforedeactivate = null;
};
}

// ie 9+ and other browsers
$e.preventDefault();
});
}

// instance methods
Expand Down