-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(typeahead): handles min-length of 0 #3600
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap | |
//SUPPORTED ATTRIBUTES (OPTIONS) | ||
|
||
//minimal no of characters that needs to be entered before typeahead kicks-in | ||
var minSearch = originalScope.$eval(attrs.typeaheadMinLength) || 1; | ||
var minSearch = originalScope.$eval(attrs.typeaheadMinLength); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe renaming to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmitriz, I could change that if it is demanded, however note that I did not change that variable name -- Cleaning up pre-existing issues in the original code seems a rather high burden to place on a 5-line PR (not counting specs) from 1.5 years ago (this is a re-PR, the original was posted in Jan of 2014). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well it was used only used in 2 places, now would be 5. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that one community members' notes and reviews aren't 'demands' on how you should do things but rather suggestions/tips. There should always be an open discussion 👍 This email was sent from my iPhone and therefore subject to typos and other inaccuracies.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmitriz, fair enough, you're right that this variable isn't really getting used elsewhere. I'll add that in. |
||
if (!minSearch && minSearch !== 0) { | ||
minSearch = 1; | ||
} | ||
|
||
//minimal wait time after last character typed before typeahead kicks-in | ||
var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0; | ||
|
@@ -193,7 +196,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap | |
|
||
hasFocus = true; | ||
|
||
if (inputValue && inputValue.length >= minSearch) { | ||
if (minSearch === 0 || inputValue && inputValue.length >= minSearch) { | ||
if (waitTime > 0) { | ||
cancelPreviousTimeout(); | ||
scheduleSearchWithTimeout(inputValue); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it only allow empty
typeahead
to open, if theinput
is focused?Otherwise several
typeahead
directives with emptyinput
s would simultaneously open at the start, which is probably not intended.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the current behavior -- see the test starting on line 563, which states an element must be focused for the typeahead to be open.
Also, I believe even on focus the typeahead will not immediately open, regardless of the limit and current input length. The typeahead only opens when the input text changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - you are right!
About immediate opening - this can be useful, for instance, to show most recent searches as soon as the user clicks or taps in the field. Would be a better UX than typing, in my view. That would seem to me the most intuitive behaviour for
minLength = 0
. Just my view, of course.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually agree with that -- especially for
minLength = 0
, but really any time, if the user has no idea what a valid input is, it could be a little clunky for them to have to start to type, then delete, in order to see all options. This would be a nice new feature to add -- an option to open on focus instead of on input change.