Mottie/Keyboard

Keyboard steals focus on initialization

downace opened this issue · 4 comments

JSFiddle: https://jsfiddle.net/6gd3y71u/24/

I have two inputs: one with the virtual keyboard, another one with autofocus.

When keyboard initializes, it steals focus from the second input.

Currently I'm using following monkey-patch to workaround this issue:

require('virtual-keyboard/dist/js/jquery.keyboard.js');

const original_checkCaretSupport = $.keyboard.checkCaretSupport;
$.keyboard.checkCaretSupport = function() {
    const focused = document.activeElement;
    original_checkCaretSupport();
    if (focused && document.activeElement !== focused && focused.focus) {
        focused.focus();
    }
};

Hi @downace!

Please use the initialFocus option to prevent the problem you're describing.

Hi!

Thanks for the response.

I've checked the initialFocus option as you suggested, it's not fixing the problem (tested on the JSFiddle I've provided in this issue).

As far as I can tell, this is not related to the normal keyboard focus.

I've used the Chrome debugger and found out that focus is lost inside $keyboard.caret method. Here is a part of the stack trace:

$keyboard.caret (jquery.keyboard.js#L3191)
$keyboard.checkCaretSupport (jquery.keyboard.js#L3175)
base.init (jquery.keyboard.js#L131)
$.keyboard (jquery.keyboard.js#L2461)
(anonymous) (jquery.keyboard.js#L3484)

Please test v1.30.4 to see if it resolves your issue. Thanks!

Hi!
I have multiple inputs When keyboard initializes, focus moves to the second input. i have tried initialFocus option but it's not working. i am used v1.30.4. stll focus moves to the next element. when there is no element enter navigation also not working.
how to prevent this issue?

Thanks in Advance!