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:
Lalit
2024-05-01 10:37:08 +05:30
committed by Tim Abbott
parent dd29edb3ad
commit 0a66fada64
2 changed files with 7 additions and 2 deletions

View File

@@ -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?.();
});

View File

@@ -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]);
});