Skip to content

[Bug]: keyboard input blocked after clicking selected items #953

@remcokalf

Description

@remcokalf

Bug description

I'm trying to integrate tom-select.js into a WordPress plugin and am running into the following.

I'm initializing it on a select element. After adding items, I found it is possible to click the items, after which isInputHidden becomes true, and the input element hides for some reason. The hiding is via a class .input-hidden. I can easily unhide it by overriding the CSS, but after that, it does not receive keyboard input.

If found the cause here:

// don't enter text in the control_input when active items are selected
if( self.isInputHidden && !isKeyDown(constants.KEY_SHORTCUT,e) ){
preventDefault(e);
}

I'm not sure what the logic is of deactivating keyboard input and hiding the input.

What I'd ideally want is:

  • that nothing happens when clicking items, there is no use for it in my case: they are already selected.
  • that the input stays visible
  • most importantly: that the input is not disabled for keyboard input.

In the docs, I see no way to disable clickability (+ all logic running after that), or any way to keep the input from hiding and being functional.

After some experimenting, I found this works to counteract the logic and fix the keyboard input. Not ideal but at least it works:

onItemSelect: function(e,item) {
    let self = this;
    setTimeout(function() {
        self.clearActiveItems();
        self.focus();
    }, 0);
},

I'm not sure if I am missing something, if this is a bug report, or a feature request.

Expected behavior

Preferably: that there would be an option that makes sure that nothing happens when clicking items:

  1. no class,
  2. no hidden input
  3. no disabling of keyboard input.

3 is the main problem, 1 and 2 can be counteracted with CSS. But a way to prevent the hiding too would also be logical. And just nothing happening would be ideal.

Steps to reproduce

  1. add some CSS to make the input visible even if hidden:
.input-hidden .ts-control > input {
    left: 0;
    opacity: 1;
    position: static;
}
  1. Click items in the dropdown
  2. Click any selected item in the control
  3. Try to use the keyboard to input text
  4. See that keyboard input is blocked, despite a blinking cursor.

Additional context

  • Tom Select v2.4.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions