feat: Trigger beforeInputUpdate when handleButtonClicked is called

This commit is contained in:
Herbert Lin 2024-05-13 23:33:00 -07:00
parent 9f917fea47
commit ea35f102e7
2 changed files with 20 additions and 0 deletions

View File

@ -465,6 +465,13 @@ class SimpleKeyboard {
*/
if (!this.input[inputName]) this.input[inputName] = "";
/**
* Perform an action before any input change
*/
if (typeof this.options.beforeInputUpdate === "function") {
this.options.beforeInputUpdate(this);
}
/**
* Calculating new input
*/

View File

@ -218,6 +218,19 @@ it('Keyboard onChange will work', () => {
expect(output).toBe("q");
});
it('Keyboard beforeInputChange will work', () => {
const mockBeforeInputUpdate = jest.fn();
const keyboard = new Keyboard({
beforeInputUpdate: mockBeforeInputUpdate,
useMouseEvents: true
});
keyboard.getButtonElement("q").onclick();
expect(mockBeforeInputUpdate).toHaveBeenCalledWith(keyboard);
});
it('Keyboard onChangeAll will work', () => {
let output;