Unable to get correct keyboard's caret position and value entered by keys are appending at the last

This issue has been tracked since 2022-10-18.

Describe the bug
Steps to reproduce:
I am trying to paste a value on the input field of keyboard using external button. But when I update the input field value with new value by calling onChange(input) and then click on any keyboard key then the values typed are appending always at the end and keyboard.caretPosition returned is null.
I tried explicitly setting the position using keyboard.caretPosition=(length of old value + length of added string). But it doesnt work and value always appends at the back.

synchronizing cursor:
//called inside onChange()
private syncCurserPosition() {
if (!this.keyboard || this.keyboard.options.disableCaretPositioning) {
return;
}
let caretPosition = this.keyboard.caretPosition;

if (caretPosition !== undefined) {
  this.inputHandler?.targetElement.setSelectionRange?.(caretPosition, caretPosition);
}

}

updating input value by pasting:
pasteValue(cursorPosition) {
const old = this.inputHandler?.targetElement.value;
const newValue = xyz +old;
const val = 3; // any length of copied value
this.onChange(newValue);
this.inputHandler!.targetElement.selectionStart =
cursorPosition + val;
}
}

Can you suggest why keyboard.caretPosition taking null after paste

More Details About Repo
Owner Name hodgef
Repo Name simple-keyboard
Full Name hodgef/simple-keyboard
Language JavaScript
Created Date 2018-03-02
Updated Date 2022-12-02
Star Count 1737
Watcher Count 20
Fork Count 130
Issue Count 0

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date