Skip to content

Commit

Permalink
feat(label): capture all events on signpost
Browse files Browse the repository at this point in the history
  • Loading branch information
dtsanevmw committed Sep 8, 2023
1 parent f9c41c0 commit 010bb33
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions projects/angular/src/forms/common/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import {
ContentChild,
Directive,
ElementRef,
HostBinding,
Expand All @@ -17,6 +18,7 @@ import {
} from '@angular/core';
import { Subscription } from 'rxjs';

import { ClrSignpost } from '../../popover';
import { ControlIdService } from './providers/control-id.service';
import { LayoutService } from './providers/layout.service';
import { NgControlService } from './providers/ng-control.service';
Expand All @@ -25,6 +27,8 @@ import { NgControlService } from './providers/ng-control.service';
selector: 'label',
})
export class ClrLabel implements OnInit, OnDestroy {
@ContentChild(ClrSignpost, { read: ElementRef }) signpost: ElementRef;

@Input('for') @HostBinding('attr.for') forAttr: string;

private enableGrid = true;
Expand All @@ -49,9 +53,7 @@ export class ClrLabel implements OnInit, OnDestroy {
*/
@HostListener('click', ['$event'])
onClick(event) {
if (event.target.hasAttribute('clrSignpostTrigger')) {
event.preventDefault();
}
this.preventOnSignpostTarget(event);
}

ngOnInit() {
Expand Down Expand Up @@ -82,4 +84,10 @@ export class ClrLabel implements OnInit, OnDestroy {
disableGrid() {
this.enableGrid = false;
}

preventOnSignpostTarget(event) {
if (this.signpost && this.signpost.nativeElement && this.signpost.nativeElement.contains(event.target)) {
event.preventDefault();
}
}
}

0 comments on commit 010bb33

Please sign in to comment.