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 4d5c056
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion projects/angular/clarity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,11 @@ export class ClrLabel implements OnInit, OnDestroy {
ngOnInit(): void;
onClick(event: any): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<ClrLabel, "label", never, { "forAttr": "for"; }, {}, never, never, false, never>;
preventOnSignpostTarget(event: any): void;
// (undocumented)
signpost: ElementRef;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<ClrLabel, "label", never, { "forAttr": "for"; }, {}, ["signpost"], never, false, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<ClrLabel, [{ optional: true; }, { optional: true; }, { optional: true; }, null, null]>;
}
Expand Down
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 4d5c056

Please sign in to comment.