p-dropdown input filter does not get focus anymore
If you have a PrimeNG PRO Support subscription please post your issue at;
https://pro.primefaces.org
where our team will respond within 4 business hours.
If you do not have a PrimeNG PRO Support subscription, fill-in the report below. Please note that your issue will be added to the waiting list of community issues and will be reviewed on a first-come first-serve basis, as a result, the support team is unable to guarantee a specific schedule on when it will be reviewed. Thank you for your understanding.
Current Waiting Time: ~8 weeks.
I'm submitting a ... (check one with "x")
[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports) The case can be seen on the site under dropdown with filters
https://www.primefaces.org/primeng/#/dropdown
Current behavior When dropdown is clicked the input filter does not get a focus as it used to. This was working before in some other versions but not anymore.
Expected behavior When filter is flagged the input filter should get focused after opening the dropdown, this was a behavior that was present in previous versions.
What is the motivation / use case for changing the behavior? This is the expected behavior and used to be working. Looking at the code it seems the filterViewChild is undefined and that is the reasons the filter doesn't get focused anymore.
Please tell us about your environment:
-
Angular version: 5.X 6.1.3
-
PrimeNG version: 5.X 6.1.2
-
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] All
Same trouble here. I found a workaround.
Instead of
https://github.com/primefaces/primeng/blob/8abb22cd37e452fd017f6c03341936de8618823c/src/app/components/dropdown/dropdown.ts#L412-L418
write
this.show();
//if (this.filterViewChild != undefined) {
setTimeout(() => {
if (this.filterViewChild != undefined)
this.filterViewChild.nativeElement.focus();
}, 200);
// }
It's not the best solution but unfortunately i can't wait for the next release.
Same problem here. We have a wrapper component for the primeng's dropdown and as a workaround we implemented (based on @Elanor-L answer) this:
onFocus() {
setTimeout(() => {
if(this.dropdownElement.filterViewChild !== undefined) {
this.dropdownElement.filterViewChild.nativeElement.focus();
}
});
}
this.dropdownElement is a ViewChild referencing to primeng's dropdown and onFocus is bind to its onFocus event.
Same works with renderer2:
onFocus() {
setTimeout(() => {
if(this.dropdownElement.filterViewChild !== undefined) {
this.renderer.selectRootElement(this.dropdownElement.filterViewChild.nativeElement).focus();
}
});
}