1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

box row directive

This commit is contained in:
Kyle Spearrin
2018-01-30 14:33:06 -05:00
parent 654b4b42a0
commit 180e28fca3
4 changed files with 96 additions and 44 deletions

View File

@@ -0,0 +1,49 @@
import {
Directive,
ElementRef,
HostListener,
OnInit,
} from '@angular/core';
@Directive({
selector: '[appBoxRow]',
})
export class BoxRowDirective implements OnInit {
el: HTMLElement = null;
formEls: NodeListOf<Element>;
constructor(private elRef: ElementRef) {
this.el = elRef.nativeElement;
}
ngOnInit(): void {
this.formEls = this.el.querySelectorAll('input:not([type="hidden"]), select, textarea');
this.formEls.forEach((formEl) => {
formEl.addEventListener('focus', (event: Event) => {
this.el.classList.add('active');
}, false);
formEl.addEventListener('blur', (event: Event) => {
this.el.classList.remove('active');
}, false);
});
}
@HostListener('click', ['$event']) onClick(event: Event) {
if (event.target !== this.el) {
return;
}
if (this.formEls.length > 0) {
const formEl = (this.formEls[0] as HTMLElement);
if (formEl.tagName.toLowerCase() === 'input') {
const inputEl = (formEl as HTMLInputElement);
if (inputEl.type != null && inputEl.type.toLowerCase() === 'checkbox') {
inputEl.checked = !inputEl.checked;
return;
}
}
formEl.focus();
}
}
}