Fix bug where event bubbles on prefix click in hint menu
Change-Id: I8a569d9183928514e69fee4faeae97f2b4253dbf
diff --git a/Changes b/Changes
index bfc13aa..8d08527 100755
--- a/Changes
+++ b/Changes
@@ -8,6 +8,8 @@
- Fix character errors in hint helper at position 0.
- Improve JS test coverage for tutorial.
- Move "use strict" to file level.
+ - Fix bug where event bubbles when prefix is clicked
+ in hint menu.
0.39 2020-10-07
- Add information on secret file to Readme.
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index a78a835..3e95e55 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -1,3 +1,5 @@
+"use strict";
+
define(['hint', 'hint/input', 'hint/contextanalyzer', 'hint/menu', 'hint/item'], function (hintClass, inputClass, contextClass, menuClass, menuItemClass) {
function emitKeyboardEvent (element, type, keyCode) {
@@ -149,7 +151,7 @@
// Intialize KorAP.context
hintClass.create();
- analyzer = contextClass.create(KorAP.context);
+ const analyzer = contextClass.create(KorAP.context);
expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c=");
expect(analyzer.test("cnx/c=")).toEqual("cnx/c=");
expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:");
@@ -171,6 +173,9 @@
describe('KorAP.Hint', function () {
+
+ let input;
+
beforeAll(beforeAllFunc);
afterAll(afterAllFunc);
@@ -387,6 +392,47 @@
hint.active().hide();
expect(hint.active()).toBeFalsy();
});
+
+ it('should support prefix', function () {
+ const hint = hintClass.create({
+ inputField : input
+ });
+ hint.inputField().reset();
+
+ expect(hint.active()).toBeFalsy();
+
+ // show with context
+ hint.show(false);
+
+ expect(hint.active()).toBeTruthy();
+
+ const menu = hint.active();
+
+ expect(menu.element().nodeName).toEqual('UL');
+
+ menu.limit(8);
+
+ // view
+ menu.show();
+
+ expect(menu.prefix()).toBe('');
+ expect(hint.active()).toBeTruthy();
+
+ // Type in prefix
+ hint.active().prefix("cor").show();
+ expect(hint.active().prefix()).toEqual("cor");
+
+ expect(input.value).toEqual("");
+ hint.active()._prefix.element().click();
+ expect(input.value).toEqual("cor");
+ expect(hint.active()).toBeFalsy();
+
+ // view
+ menu.show();
+ expect(menu.prefix()).toBe('');
+
+ });
+
xit('should remove all menus on escape');
});
diff --git a/dev/js/src/hint/menu.js b/dev/js/src/hint/menu.js
index b7e0d49..89f1d10 100644
--- a/dev/js/src/hint/menu.js
+++ b/dev/js/src/hint/menu.js
@@ -21,7 +21,7 @@
* Create new hint helper menu.
*/
create : function (hint, context, params) {
- var obj = Object.create(menuClass)
+ const obj = Object.create(menuClass)
.upgradeTo(this)
._init(params, {
itemClass : itemClass,
@@ -41,7 +41,7 @@
// Focus on input field on hide
obj.onHide = function () {
- var h = this._hint;
+ const h = this._hint;
h._inputField.element().focus();
if (h.active() !== null) {
if (h._alert.active) {
diff --git a/dev/js/src/hint/prefix.js b/dev/js/src/hint/prefix.js
index 5a83284..1a673f8 100644
--- a/dev/js/src/hint/prefix.js
+++ b/dev/js/src/hint/prefix.js
@@ -14,14 +14,15 @@
/**
* Override the prefix action.
*/
- onclick : function () {
+ onclick : function (e) {
const m = this.menu();
const value = this.value();
const h = m.hint();
- m.hide();
-
h.inputField().insert(value);
- h.active = false;
+ h.active(null);
+ m.hide();
+ // h.unshow();
+ e.halt();
}
};
});