mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
input_pill: Use "input" event handler for textInputHook.
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 update the text content before running the hook.
This commit is contained in:
@@ -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?.();
|
||||
});
|
||||
|
||||
|
||||
@@ -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]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user