-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight first item in AutoComplete #2040
Comments
We reviewed this and this is expected behaviour. |
Is there any way to programmatically default to the first item in the suggestion list, without having to click the down arrow key? This makes even more sense if there's only one option is the suggestion list. Currently, the user always has to use the down arrow key to select the value, which seem redundant and forces an extra keyboard transaction for every search. E.g Spain should be preselected here |
@davladus I was able to get this functionality by dispatching a down arrow key event to the autocomplete component at the end of the import { AutoComplete } from 'primeng/primeng'; @ViewChild(AutoComplete) primeAutoCompleteComponent: AutoComplete; // (completeMethod)="search($event)"
search(event?: any) {
// filter you search results array
. . .
this.preSelectFirstOptionInResultsList();
} private preSelectFirstOptionInResultsList(): void {
setTimeout(() => {
let highlightItemIndex = this.primeAutoCompleteComponent.findOptionIndex(this.primeAutoCompleteComponent.highlightOption);
if (highlightItemIndex < 0) {
var arrowDownEvent = document.createEvent('Event');
(<any>arrowDownEvent).initEvent('keydown', { "bubbles": false, "cancelable": false });
Object.defineProperty(arrowDownEvent, 'which', { 'value': 40 });
(<Node>this.primeAutoCompleteComponent.input).dispatchEvent(arrowDownEvent);
}
}, 0);
} |
the feature is already implemented in version 16.9.3lst,
|
**I'm submitting a usability bug
Plunkr Case (Bug Reports)
http://www.primefaces.org/primeng/#/autocomplete
Current/Expected behavior
Minimal reproduction of the problem with instructions
When I start typing letters (Advanced sample)
And selection dropdown is expanded
Then
Observed: nothing selected
Expected: first filtered item is selected
Please tell us about your environment:
Window 7, Chrome
The text was updated successfully, but these errors were encountered: