UKHomeOffice / typeahead-aria

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.com/UKHomeOffice/typeahead.js/
MIT License
9 stars 3 forks source link

Fix for unhandled selectableRelativeToCursor null return value #5

Closed colinrotherham closed 7 years ago

colinrotherham commented 7 years ago

When using the arrow keys to move the selection up/down, there's a script error when moving beyond the first/last item in the list.

Why?

The code in moveCursor() assumes the return value from selectableRelativeToCursor() is always a jQuery selector, yet it can actually be null.

For example, when arrowing “out of bounds”, $candidate here is null:

$candidate = this.menu.selectableRelativeToCursor(delta);

This causes the following:

$candidate.attr("id")

To throw an error: Uncaught TypeError: Cannot read property 'attr' of null(…)

I've also re-run the grunt tasks so various files in ./dist have been recreated.

colinrotherham commented 7 years ago

I'd also consider moving upstream to a maintained fork of the Twitter typeahead, here's one that's actively worked on: https://github.com/corejavascript/typeahead.js

The ARIA additions could be patched on this version instead.