Unable to get correct keyboard's caret position and value entered by keys after upating input in middle are appending at the last

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

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 end.

synchronizing cursor after input field updated:
//called inside onChange()
private syncCurserPosition() {
if (!this.keyboard || this.keyboard.options.disableCaretPositioning) {
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.inputHandler!.targetElement.selectionStart =
cursorPosition + val;

Can you suggest why keyboard.caretPosition taking null after paste.

hodgef wrote this answer on 2022-10-22

Hey @Niharika-Pat,

Please provide a full repro. It can be a sandbox or a test git repository. This will be more useful for debugging.

Francisco Hodge

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-06
Star Count 1738
Watcher Count 20
Fork Count 130
Issue Count 0


Issue Title Created Date Updated Date