Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typeahead: Fix the bug where clicking by JS, selected the wrong elem.

Riken Shah6c6b6643ce91
diff --git a/static/third/bootstrap-typeahead/typeahead.js b/static/third/bootstrap-typeahead/typeahead.js
index 2953ce68187..74e1f3f7ecc 100644
--- a/static/third/bootstrap-typeahead/typeahead.js
+++ b/static/third/bootstrap-typeahead/typeahead.js
@@ -326,7 +326,7 @@
}
this.$menu
- .on('click', this.click.bind(this))
+ .on('click', 'li', this.click.bind(this))
.on('mouseenter', 'li', this.mouseenter.bind(this))
}
@@ -428,6 +428,14 @@
, click: function (e) {
e.stopPropagation()
e.preventDefault()
+ // The original bootstrap code expected `mouseenter` to be called
+ // to set the active element before `select()`.
+ // Since select() selects the element with the active class, if
+ // we trigger a click from JavaScript (or with a mobile touchscreen),
+ // this won't work. So we need to set the active element ourselves,
+ // and the simplest way to do that is to just call the `mouseenter`
+ // handler here.
+ this.mouseenter(e)
this.select(e)
}