Mottie / Keyboard

Virtual Keyboard using jQuery ~
http://mottie.github.io/Keyboard/
Other
1.77k stars 722 forks source link

Keyboard steals focus on initialization #811

Closed downace closed 2 years ago

downace commented 2 years ago

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();
    }
};
Mottie commented 2 years ago

Hi @downace!

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

downace commented 2 years ago

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)

Mottie commented 2 years ago

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

nagamounika1513 commented 8 months ago

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!