angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.29k stars 6.73k forks source link

typeahead-focus-first should select first if user has partially entered a value #6431

Open peder opened 7 years ago

peder commented 7 years ago

In the getMatchesAsync function, the activeIdx is set to 0 if focusFirst is true and always to -1 if false. I would argue that if user has already entered a partial value and then hits tab, the user would want that value to be selected. Instead, hitting tab without first hitting the down arrow results in no value being selected.

For instance, given a company field with values ['ABC Corp', 'XYZ Corp'] and typeahead-focus-first='false', if a user clicks into the field, both values appear but neither is selected. If the user types in ABC, I think ABC Corp should become the selected value. It seems like this would be more intuitive then forcing the user to hit the down arrow--they could just hit Tab after typing ABC.

Current: scope.activeIdx = focusFirst ? 0 : -1;

Proposed: scope.activeIdx = focusFirst ? 0 : inputValue && inputValue.length ? 0 : -1;

icfantv commented 7 years ago

@peder, in the future, please adhere to the issue template. It's there for a reason. I'm going to leave this open, however, as you've already submitted a PR. Please note that that PR needs work.

peder commented 7 years ago

I'll get this and the PR cleaned up.