What are you trying to do?
Setting an item in my panel active programmatically.
What are you seeing that does not match your expectations?
Using autocomplete's keymanager function setActiveItem doesn't actually update the visuals of the panel at all. When triggering a visual update manually it works on mouse-click but not when navigating with the keyboard.
Reproduction
StackBlitz demo
Steps to reproduce:
Show More.Show More with the keyboard.SetActiveItem doesn't work at all.Environment
Looking for tips on how to get this working. Is my approach wrong or does setActiveItem not work the way it should? In the function annotations, it is described as:
Sets the active item to the item to the specified one and adds the active styles to it. Also removes active styles from the previously active item.
That sounds like the exact functionality I need but I can't get it to work.
I had to use setTimeout. The fix was:
setTimeout(() => {
this.matSelect._keyManager.setActiveItem(1);
this.matSelect._keyManager.setActiveItem(2);
}, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With