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.

input_pill: Use "input" event handler for `textInputHook`.

Lalit0a66fada64d7
diff --git a/web/src/input_pill.ts b/web/src/input_pill.ts
index 7adc29a44ee..b6dc3a1ea54 100644
--- a/web/src/input_pill.ts
+++ b/web/src/input_pill.ts
@@ -370,7 +370,12 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
return;
}
+ });
+ // Register our `onTextInputHook` to be called on "input" events so that
+ // the hook receives the updated text content of the input unlike the "keydown"
+ // event which does not have the updated text content.
+ store.$parent.on("input", ".input", () => {
store.onTextInputHook?.();
});
diff --git a/web/tests/input_pill.test.js b/web/tests/input_pill.test.js
index 01d610ff60c..c9970c07bf6 100644
--- a/web/tests/input_pill.test.js
+++ b/web/tests/input_pill.test.js
@@ -664,7 +664,7 @@ run_test("getCurrentText/onTextInputHook", ({mock_template}) => {
$pill_input.text("yellow");
assert.equal(widget.getCurrentText(), "yellow");
- const key_handler = $container.get_on_handler("keydown", ".input");
+ const key_handler = $container.get_on_handler("input", ".input");
key_handler({
key: " ",
preventDefault: noop,
@@ -674,5 +674,5 @@ run_test("getCurrentText/onTextInputHook", ({mock_template}) => {
preventDefault: noop,
});
- assert.deepEqual(widget.items(), [items.blue, items.red, items.yellow]);
+ assert.deepEqual(widget.items(), [items.blue, items.red]);
});