Ensure caret position is not lost when using syncInstanceInputs. Fixes https://github.com/hodgef/react-simple-keyboard/issues/1948

This commit is contained in:
Francisco Hodge 2022-06-09 22:58:10 -07:00
parent 6dbf28364e
commit a2d537bfe2

View File

@ -887,6 +887,7 @@ class SimpleKeyboard {
}
this.keyboardDOM.className = this.keyboardDOMClass;
this.keyboardDOM.setAttribute("data-skInstance", this.currentInstanceName);
this.buttonElements = {};
}
@ -1157,10 +1158,20 @@ class SimpleKeyboard {
}
this.dispatch((instance) => {
const isKeyboard =
let isKeyboard =
event.target === instance.keyboardDOM ||
(event.target && instance.keyboardDOM.contains(event.target));
/**
* If syncInstanceInputs option is enabled, make isKeyboard match any instance
* not just the current one
*/
if (this.options.syncInstanceInputs && Array.isArray(event.path)) {
isKeyboard = event.path.some((item: HTMLElement) =>
item?.hasAttribute?.("data-skInstance")
);
}
if (
(targetTagName === "textarea" ||
(targetTagName === "input" &&
@ -1297,6 +1308,11 @@ class SimpleKeyboard {
*/
this.activeInputElement = null;
/**
* Removing instance attribute
*/
this.keyboardDOM.removeAttribute("data-skInstance");
/**
* Clearing keyboardDOM
*/
@ -1677,6 +1693,11 @@ class SimpleKeyboard {
useTouchEventsClass
);
/**
* Adding keyboard identifier
*/
this.keyboardDOM.setAttribute("data-skInstance", this.currentInstanceName);
/**
* Create row wrapper
*/