0

I have 3 element. when the user focusout on the last element, I am redirecting back to first element instead of focusing on browser elements. but it's not working. I am not able to prevent the foucusout how to handle this? How to stop before focusout and redirect to another method.

here is the snippet of my code :

 @HostListener('document:focusout', ['$event']) public DocFocus($event) {
$event.preventDefault();//not works
if (this.lastFocusElement && this.lastFocusElement === $event.target) {
  this.setFocus();//got to fist element 
  console.log('done', this.firstFocusElement);
}

}

on focusout, now my tab going to browser address bar.

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • seems `stopImmediatePropagation` may not be supported by Angular - https://stackoverflow.com/questions/57852324/prevent-angular-hostlistener-propagation-to-parent-component – Marshal Aug 27 '21 at 18:04
  • maybe `stopPropagation` is a viable option. - https://stackoverflow.com/questions/35274028/stop-mouse-event-propagation – Marshal Aug 27 '21 at 18:11

0 Answers0