Skip to main content

Search and Top Navigation

#15271 new bug ()

Opened February 14, 2018 07:00AM UTC

Last modified February 14, 2018 07:00AM UTC

Autocomplete menu selecting wrong item on click in tests

Reported by: bennieswart Owned by:
Priority: minor Milestone: none
Component: Version: 1.12.1
Keywords: Cc:
Blocked by: Blocking:

During automated testing the autocomplete menu sometimes selects the wrong item upon click.

This can be reproduced by making a page with a normal autocomplete input with a couple of options.

The tests populate the text of the input after which the menu opens. Then, the desired item is clicked. Even though the click event reports the correct item was clicked, the item which is actually selected by the autocomplete plugin may be a different one.

I could only reproduce this in automated tests and not by hand. The issue is most probably related to the tests not firing all events that would fire during normal operation. This is actually mentioned in a comment in Menu#select (

// TODO: It should never be possible to not have an active item at this
// point, but the tests don't trigger mouseenter before click.

The item to be selected is determined by the following line: = || $( ).closest( ".ui-menu-item" );

Thus, if 
has not been properly set by preceding events, the wrong element may be selected.

I propose the following: = $( ).is( ".ui-menu-item" ) ? $( ) : || $( ).closest( ".ui-menu-item" );

In other words, if the target element is a menu item, then it is used as the active element. Otherwise, determine the active element as per usual. One might even add an explicit check for the event type, if necessary.

I'm seeing this in 1.11.4, but the error is still present in master at the time of writing (1.12.1).


  • jQuery 2.1.4
  • Chrome 63
  • Ubuntu 16.04 and Arch

I will submit a PR if the proposed solution is deemed viable.

Attachments (0)
Change History (0)