Currently in my Angular 14 project, I am working on a feature where I need to apply "display: block" to an element once the user reaches it using the tab key. However, I am struggling with removing the "display: block" when the user tabs out of the element.
I have successfully implemented the first part of adding "display: block" when the element is reached via the tab key. But I am unsure about how to handle removing it when the user tabs out.
@HostListener('document:keydown.tab', ['$event'])onKeydownHandler(event: KeyboardEvent) {
if (event.key === "Tab" && (event.target as Element).classList.contains('some-class')) {
this.renderer.addClass(this.test?.nativeElement, 'd-block');
}}
I would appreciate some assistance. Is there a more effective approach to achieve this functionality without relying solely on host listeners?