From 20d24d97fd6c1d172e4633b272cd38281ea86040 Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Thu, 18 Apr 2019 10:13:02 -0400 Subject: [PATCH] caretPosition reset when inputName is changed through setOptions --- src/lib/components/Keyboard.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/lib/components/Keyboard.js b/src/lib/components/Keyboard.js index 64f5e398..4582cc1b 100644 --- a/src/lib/components/Keyboard.js +++ b/src/lib/components/Keyboard.js @@ -363,14 +363,40 @@ class SimpleKeyboard { /** * Set new option or modify existing ones after initialization. - * @param {object} option The option to set + * @param {object} options The options to set */ - setOptions = option => { - option = option || {}; - this.options = Object.assign(this.options, option); + setOptions(options){ + options = options || {}; + this.options = Object.assign(this.options, options); + + /** + * Some option changes require adjustments before re-render + */ + this.onSetOptions(options); + + /** + * Rendering + */ this.render(); }; + /** + * Executing actions depending on changed options + * @param {object} options The options to set + */ + onSetOptions(options){ + if(options.inputName){ + /** + * inputName changed. This requires a caretPosition reset + */ + if (this.options.debug) { + console.log("inputName changed. caretPosition reset."); + } + + this.caretPosition = null; + } + } + /** * Remove all keyboard rows and reset keyboard values. * Used interally between re-renders.