diff --git a/src/lib/components/Keyboard.js b/src/lib/components/Keyboard.js index 29afd47c..cf0fdaaa 100644 --- a/src/lib/components/Keyboard.js +++ b/src/lib/components/Keyboard.js @@ -296,6 +296,7 @@ class SimpleKeyboard { syncInstanceInputs() { this.dispatch(instance => { instance.replaceInput(this.input); + instance.caretPosition = this.caretPosition; }); } @@ -354,11 +355,6 @@ class SimpleKeyboard { */ replaceInput(inputObj) { this.input = inputObj; - - /** - * Reset caretPosition - */ - this.caretPosition = null; } /** diff --git a/src/lib/components/tests/Keyboard.test.js b/src/lib/components/tests/Keyboard.test.js index e7a367fc..98604649 100644 --- a/src/lib/components/tests/Keyboard.test.js +++ b/src/lib/components/tests/Keyboard.test.js @@ -168,6 +168,26 @@ it('Keyboard syncInstanceInputs will work', () => { keyboard1.getButtonElement("q").onclick(); expect(keyboard2.getInput()).toBe("q"); + + /** + * Test cursor syncing... + * Reinit keyboards + */ + keyboard1 = new Keyboard(".keyboard1", sharedOptions); + keyboard2 = new Keyboard(".keyboard2", sharedOptions); + + keyboard1.getButtonElement("1").onclick(); + keyboard1.getButtonElement("5").onclick(); + keyboard1.getButtonElement("6").onclick(); + + keyboard1.caretPosition = 1; + + keyboard1.getButtonElement("2").onclick(); + keyboard1.getButtonElement("3").onclick(); + keyboard1.getButtonElement("4").onclick(); + + expect(keyboard1.getInput()).toBe("123456"); + expect(keyboard2.getInput()).toBe("123456"); }); it('Keyboard onChange will work', () => {