diff --git a/src/lib/components/Keyboard.ts b/src/lib/components/Keyboard.ts index c86d0f2e..76cddcba 100644 --- a/src/lib/components/Keyboard.ts +++ b/src/lib/components/Keyboard.ts @@ -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 */ diff --git a/src/lib/components/tests/Keyboard.test.js b/src/lib/components/tests/Keyboard.test.js index bd372dff..ece2828b 100644 --- a/src/lib/components/tests/Keyboard.test.js +++ b/src/lib/components/tests/Keyboard.test.js @@ -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;